﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using System.Collections;
namespace LCWMS
{
    public partial class w_inv013 : DockContent
    {
        
        public static DataTable dt_save, modify;
        private DataSet dscustomer;
        private DataSet dsmove_header;
        private DataSet dsmove_detail;
        private DataSet dsmove_con;
        private DataSet dsmove_mv;
        string str_sql_where = "";
        string move_no_str = "";
        public decimal L_qty = 0;
        public int g_str_oper = 0;
        public string str_sql_mv = "";
        public string str_sql_con = "", str_type="0";
        string str_update_sql = "";
        string g_str_status;
        int g_round = 0;
        int g_line_no = 0;
        public void ClearCntrValue(Control parContainer, bool bol, string edit)
        {
            for (int index = 0; index < parContainer.Controls.Count; index++)
            {
                // 如果是容器类控件，递归调用自己
                if (parContainer.Controls[index].HasChildren)
                {
                    // ClearCntrValue(parContainer.Controls[index]);
                }
                else
                {

                    switch (parContainer.Controls[index].GetType().Name)
                    {

                        case "TextBox":

                            if (edit != "1")
                            {
                                parContainer.Controls[index].Text = "";
                            }

                            if (bol == false)
                                ((TextBox)parContainer.Controls[index]).ReadOnly = true;
                            else
                                ((TextBox)parContainer.Controls[index]).ReadOnly = false;
                            break;
                        case "RadioButton":
                            if (edit != "1")
                                ((RadioButton)(parContainer.Controls[index])).Checked = false;
                            ((RadioButton)(parContainer.Controls[index])).Enabled = bol;
                            break;
                        case "CheckBox":
                            if (edit != "1")
                                ((CheckBox)(parContainer.Controls[index])).Checked = false;

                            ((CheckBox)(parContainer.Controls[index])).Enabled = bol;
                            break;
                        case "ComboBox":
                            if (edit != "1")
                                //((ComboBox)(parContainer.Controls[index])).SelectedIndex = 0;
                                ((ComboBox)(parContainer.Controls[index])).Enabled = bol;
                            break;
                        case "DateTimePicker":
                            if (edit != "1")
                                ((DateTimePicker)(parContainer.Controls[index])).Text = "";
                            ((DateTimePicker)(parContainer.Controls[index])).Enabled = bol;
                            break;
                    }

                }
            }
        }
        //判断库们是否合法
        private void f_checkloc(string str_tmp1, string str_tmp2, string str_tmp3, string str_tmp4, decimal d_qty, string str_tmp5)
        {
            
            string str_loc = "";
            try
            {
                if (main.dbtype == "SQL")
                {
                    str_loc = main.dbservice.Sql_exec_proc_moveloc(main.g_org, str_tmp1, str_tmp2, str_tmp3, str_tmp4, d_qty, str_tmp5);
                }
                else
                {
                    str_loc = main.dbservice.oracle_exec_proc_moveloc(main.g_org, str_tmp1, str_tmp2, str_tmp3, str_tmp4, d_qty, str_tmp5);
                }
            }

            catch (System.Exception ee)
            {
                MessageBox.Show(main.g_class.comm_getchangestring("Fail to get location  Information  !", main.g_info_dataset) + ee.ToString());
                Cursor.Current = Cursors.Default;
                return;
            }
            if (str_loc == "UNKNOWN")
            {
                MessageBox.Show(main.g_class.comm_getchangestring("Fail to get location  Information  !", main.g_info_dataset));
                return;
            }
        }
        public w_inv013()
        {

            InitializeComponent();
            dataGridView3.AutoGenerateColumns = false;
            dataGridView2.AutoGenerateColumns = false;
            dataGridView1.AutoGenerateColumns = false;
        }
        //根据条件显示移库信息与确认信息
        private void f_move_distplay()
        {
            string str_sql = "";

            string where1 = "";
            string where2 = "";
            where1 = " and moveout_pallet='0' and batchno='0' and  move_status='0'  and main_dist <> 'D'";
            where2 = " and moveout_pallet<>'0' and batchno<>'0'and main_dist <> 'D'";
            move_no_str = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["move_no_h"].Value.ToString().Trim();
            str_sql_where = "inv_org = '" + main.g_org + "' and consignor='" + dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["consignor"].Value.ToString().Trim() + "' and move_no='" + dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["move_no_h"].Value.ToString().Trim() + "'";
            DataRow[] tr_header = dsmove_header.Tables[0].Select(str_sql_where);

            if (tr_header.Length > 0)
            {
                show(tr_header[0]);

                dsmove_mv = new DataSet();
                dsmove_con = new DataSet();
                str_sql = "select a.*,confirm_qty_m as old_confirm_qty_m,0.0 temp_qty from " + main.g_space + ".inv_move_detail a where " + str_sql_where;
                if (main.dbtype == "SQL")
                {
                    str_sql_mv = str_sql + where1;
                    dsmove_mv = main.dbservice.Sql_exec_selectsql(str_sql_mv);
                    str_sql_con = str_sql + where2;
                    dsmove_con = main.dbservice.Sql_exec_selectsql(str_sql_con);


                }
                else
                {
                    str_sql_mv = str_sql + where1;
                    dsmove_mv = main.dbservice.oracle_exec_selectsql(str_sql_mv);
                    str_sql_con = str_sql + where2;
                    dsmove_con = main.dbservice.oracle_exec_selectsql(str_sql_con);
                }
                dataGridView2.DataSource = dsmove_mv.Tables[0];

                dataGridView3.DataSource = dsmove_con.Tables[0];
                g_str_oper = 0;
                this.bt_Close.Enabled = true;
                this.bt_Direction.Enabled = true;
                this.bt_Confirm.Enabled = false;
                this.bt_Cancel.Enabled = false;
            }
        }
        //修改时判断库位是否可用
        private void f_modfy_loc(string str_outlocation, string str_batchno, string str_customer, string str_skus, decimal d_outqty)
        {
            DataSet ds_str1 = new DataSet();
            DataSet ds_str2 = new DataSet();
            DataSet ds_str3 = new DataSet();
            DataSet ds_str4 = new DataSet();
            DataSet ds_str5 = new DataSet();

            string str1 = "select mix_sku,mix_lotno from " + main.g_space + ".mst_location where inv_org = '" + main.g_org + "' and location_code='" + str_outlocation + "'";
            string str3 = "select distinct(sku) from " + main.g_space + ".inv_sku_location where inv_org = '" + main.g_org + "' and location_code='" + str_outlocation + "'";
            string str_sku = "select b.*,a.mix_lotno,a.mix_sku from " + main.g_space + ".mst_sku a left join  " + main.g_space + ".inv_sku_location b on a.inv_org = b.inv_org and a.sku=b.sku where b.inv_org = '" + main.g_org + "' and b.location_code='" + str_outlocation + "' and b.consignor='" + str_customer + "'";
            if (main.dbtype == "SQL")
            {
                ds_str1 = main.dbservice.Sql_exec_selectsql(str1);
                ds_str3 = main.dbservice.Sql_exec_selectsql(str3);
                ds_str5 = main.dbservice.Sql_exec_selectsql(str_sku);
            }
            else
            {
                ds_str1 = main.dbservice.oracle_exec_selectsql(str1);
                ds_str3 = main.dbservice.oracle_exec_selectsql(str3);
                ds_str5 = main.dbservice.oracle_exec_selectsql(str_sku);
            }
            if (ds_str3.Tables[0].Rows.Count > 0)//判断库位是否为空库位
            {
                if (ds_str3.Tables[0].Rows[0]["sku"].ToString().Trim() == str_skus)//判断移入商品是否与库位上是同一种商品
                {
                    if (ds_str1.Tables[0].Rows[0]["mix_lotno"].ToString().Trim() == "1" && ds_str5.Tables[0].Rows[0]["mix_lotno"].ToString().Trim() == "1")//是否可以混批次
                    {
                        //可以混批次
                        Judge(str_outlocation, d_outqty);
                    }
                    else
                    {
                        string str_out_batchno = "select batchno from " + main.g_space + ".inv_sku_pallet where inv_org = '" + main.g_org + "' and location_code='" + str_outlocation + "' and pallet_no =(select min(pallet_no) from " + main.g_space + ".inv_sku_pallet where inv_org = '" + main.g_org + "' and  location_code='" + str_outlocation + "')";

                        //string str_batchno = "select batchno from wms.inv_sku_pallet where location_code='" + tb_moveout_location.Text.Trim() + "' and  sku='" + cb_moveout_sku.Text.Trim() + "' and  consignor='" + cbx_h_consignor.Text.Trim() + "'";
                        //DataSet ds_batchno = new DataSet();
                        DataSet ds_out_batchno = new DataSet();
                        if (main.dbtype == "SQL")
                        {
                            //ds_batchno = main.dbservice.Sql_exec_selectsql(str_batchno);
                            ds_out_batchno = main.dbservice.Sql_exec_selectsql(str_out_batchno);
                        }
                        else
                        {
                            //ds_batchno = main.dbservice.oracle_exec_selectsql(str_batchno);
                            ds_out_batchno = main.dbservice.oracle_exec_selectsql(str_out_batchno);
                        }
                        if (str_batchno == ds_out_batchno.Tables[0].Rows[0][0].ToString().Trim())//判断是否是相同批次
                        {
                            //同一批次
                            Judge(str_outlocation, d_outqty);
                        }
                        else
                        {
                            MessageBox.Show(main.g_class.comm_getchangestring("" + str_outlocation + "The location can't deposit sku of mixed batch", main.g_info_dataset) + "!");
                            return;
                        }
                    }
                }
                else
                {
                    if (ds_str1.Tables[0].Rows[0]["mix_sku"].ToString().Trim() == "1" && ds_str5.Tables[0].Rows[0]["mix_sku"].ToString().Trim() == "1")//是否可以混批次
                    {
                        //可以混商品
                        Judge(str_outlocation, d_outqty);
                    }
                    else
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("" + str_outlocation + "The location can't deposit sku of mixed batch", main.g_info_dataset) + "!");
                        return;
                    }
                }
            }


        }
        //判断库存的库位的托盘数量
        private void Judge(string str_outloc, decimal d_outqty)
        {
            DataSet ds_str = new DataSet();
            string str = "";
            str = "select leftcount  from " + main.g_space + ".VIEW_SQL_PL_LOC where inv_org = '" + main.g_org + "' and  location_code='" + str_outloc + "'";
            if (main.dbtype == "SQL")
            {
                ds_str = main.dbservice.Sql_exec_selectsql(str);
            }
            else
            {
                ds_str = main.dbservice.oracle_exec_selectsql(str);
            }
            if (ds_str.Tables[0].Rows.Count > 0)
            {
                if (Convert.ToDecimal(ds_str.Tables[0].Rows[0][0]) < d_outqty)//判断库位是否可用
                {
                    MessageBox.Show(main.g_class.comm_getchangestring("" + str_outloc + "Location code lack of capacity can not be moved sku!", main.g_info_dataset) + "!");

                    return;
                }
            }
        }


        private void cb_consignor_TextChanged(object sender, EventArgs e)
        {
            string str_cust;
            str_cust = cb_consignor.Text.Trim();
            tb_cusname.Text = main.g_class.comm_findname(str_cust, dscustomer);
        }
        private void show(DataRow tr)
        {

            this.cbx_h_consignor.Text = tr["consignor"].ToString().Trim();
            this.tb_h_consignor_name.Text = tr["consignor_name"].ToString().Trim();
            this.cb_move_type.SelectedIndex = Convert.ToInt32(tr["move_type"].ToString().Trim());
            this.cb_h_move_status.Text = tr["move_status"].ToString().Trim();
            // this.cbx_h_move_reason.SelectedValue = Convert.ToInt32(tr["move_reason"].ToString().Trim());

            this.tb_h_move_no.Text = tr["move_no"].ToString().Trim();
            this.tb_h_memo.Text = tr["memo"].ToString().Trim();
            comboBox2.SelectedValue = tr["transaction_type"].ToString().Trim();
        }
        private void btn_Query_Click(object sender, EventArgs e)
        {
            string where1 = "";
            string where2 = "";
            string str_sql = "";
            str_sql_where = " where a.inv_org = '" + main.g_org + "' and a.move_type='0' and  a.main_dist<>'D' ";
            if (cb_consignor.Text.ToString().Trim() != "")
            {
                str_sql_where += " and a.consignor='" + cb_consignor.Text.ToString().Trim() + "' ";
            }
            else
            {
                str_sql_where += " and  a.consignor in (select mst_1.consignor from " + main.g_space + ".mst_customer mst_1," + main.g_space + ".sys_user mst_2," + main.g_space + ".sys_user_customer mst_3" +
                             " where mst_2.inv_org = mst_3.inv_org and mst_2.user_id = mst_3.user_id and mst_3.inv_org = mst_1.inv_org and mst_3.consignor = mst_1.consignor and mst_2.inv_org = '" + main.g_org + "' and mst_2.user_id = '" + main.g_user + "' and mst_1.consignor_flag='1' )";
            }
            if (comboBox1.Text.Trim() != "")
            {
                str_sql_where += " and a.standby_5='" + comboBox1.SelectedValue.ToString().Trim() + "' ";
            }
            if (tb_move_no.Text.ToString().Trim() != "")
            {
                str_sql_where += " and a.move_no='" + tb_move_no.Text.ToString().Trim() + "' ";
            }
            if (dtp_made_time.Text.ToString().Trim() != "" || dtp_made_time_end.Text.ToString().Trim() != "")
            {
                if (main.dbtype == "SQL")
                    str_sql_where += " and  CONVERT(varchar(10) , a.made_time, 102 )  between     '" + dtp_made_time.Text.Trim() + "' and '" + dtp_made_time_end.Text + "'";
                else
                    str_sql_where += " and to_char(a.made_time,'yyyy.mm.dd')  between     '" + dtp_made_time.Text.Trim() + "' and '" + dtp_made_time_end.Text + "'";
            }
            if (cb_q_status.Text.Trim() != "")
            {
                if (cb_q_status.SelectedIndex > -1)
                {
                    str_sql_where += " and a.move_status='" + cb_q_status.SelectedIndex + "'";
                }
            }
            str_sql_where += "  and a.standby_4='1' ";
            if (main.dbtype == "SQL")
            {
                str_sql = "select b.consignor_name,a.inv_org,a.consignor,a.move_no,case rtrim(ltrim(a.standby_5)) when '01' then '" + main.g_class.comm_getchangestring("import store", main.g_info_dataset) + "' when '02' then '" + main.g_class.comm_getchangestring("borrow store", main.g_info_dataset) + "' when '03' then '" + main.g_class.comm_getchangestring("kanban store", main.g_info_dataset) + "' else '" + main.g_class.comm_getchangestring("move", main.g_info_dataset) + "' end  transaction_type2,a.standby_5 transaction_type,case a.move_status when '0' then '" + main.g_class.comm_getchangestring("make", main.g_info_dataset) + "' " +
               "when '1' then '" + main.g_class.comm_getchangestring("part confirm", main.g_info_dataset) + "'when '2' then '" + main.g_class.comm_getchangestring("confirm", main.g_info_dataset) + "'" +
               "else  '" + main.g_class.comm_getchangestring("closed", main.g_info_dataset) + "'end as move_status,a.move_type,a.move_reason,a.wave_dist,a.wave_no,a.standby_1,a.standby_2,a.standby_3,a.standby_4," +
               "a.standby_5,a.standby_6,a.standby_7,a.confirm_day,a.confirmer,a.memo,a.main_dist,a.maker,a.made_time from " + main.g_space + ".inv_move_header  a left join " + main.g_space + ".mst_customer b on b.inv_org = a.inv_org and b.consignor=a.consignor " + str_sql_where;
            }
            else
            {
                str_sql = "select b.consignor_name,a.inv_org,a.consignor,a.move_no,case trim(a.standby_5) when '01' then '" + main.g_class.comm_getchangestring("import store", main.g_info_dataset) + "' when '02' then '" + main.g_class.comm_getchangestring("borrow store", main.g_info_dataset) + "' when '03' then '" + main.g_class.comm_getchangestring("kanban store", main.g_info_dataset) + "' else '" + main.g_class.comm_getchangestring("move", main.g_info_dataset) + "' end  transaction_type2 ,a.standby_5 transaction_type,case a.move_status when '0' then '" + main.g_class.comm_getchangestring("make", main.g_info_dataset) + "' " +
                "when '1' then '" + main.g_class.comm_getchangestring("part confirm", main.g_info_dataset) + "'when '2' then '" + main.g_class.comm_getchangestring("confirm", main.g_info_dataset) + "'" +
                "else  '" + main.g_class.comm_getchangestring("closed", main.g_info_dataset) + "'end as move_status,a.move_type,a.move_reason,a.wave_dist,a.wave_no,a.standby_1,a.standby_2,a.standby_3,a.standby_4," +
                "a.standby_5,a.standby_6,a.standby_7,a.confirm_day,a.confirmer,a.memo,a.main_dist,a.maker,a.made_time from " + main.g_space + ".inv_move_header  a left join " + main.g_space + ".mst_customer b on b.inv_org = a.inv_org and b.consignor=a.consignor  " + str_sql_where;
            }
            try
            {
                dsmove_header = new DataSet();
                if (main.dbtype == "SQL")
                {
                    dsmove_header = main.dbservice.Sql_exec_selectsql(str_sql);
                }
                else
                {
                    dsmove_header = main.dbservice.oracle_exec_selectsql(str_sql);
                }
                dataGridView1.DataSource = dsmove_header.Tables[0];
                if (dsmove_header.Tables[0].Rows.Count > 0)
                {
                    dsmove_detail = new DataSet();
                    show(dsmove_header.Tables[0].Rows[0]);
                    if (str_type == "0")//按照原来的方式 操作不变
                    {
                        str_sql = "select e.*,confirm_qty_m as old_confirm_qty_m from " + main.g_space + ".inv_move_detail e where inv_org = '" + main.g_org + "' and move_no='" + dsmove_header.Tables[0].Rows[0]["move_no"].ToString().Trim() + "' and consignor='" + dsmove_header.Tables[0].Rows[0]["consignor"].ToString().Trim() + "'";
                      
                        move_no_str = dsmove_header.Tables[0].Rows[0]["move_no"].ToString().Trim();
                        dsmove_mv = new DataSet();
                        dsmove_con = new DataSet();
                        where1 = " and moveout_pallet='0' and batchno='0' and main_dist <> 'D' ";
                        where2 = " and moveout_pallet<>'0' and batchno<>'0' and main_dist <> 'D' ";
                        if (main.dbtype == "SQL")
                        {

                            str_sql_mv = str_sql + where1;
                            dsmove_mv = main.dbservice.Sql_exec_selectsql(str_sql_mv);
                            str_sql_con = str_sql + where2;
                            dsmove_con = main.dbservice.Sql_exec_selectsql(str_sql_con);

                        }
                        else
                        {
                            str_sql_mv = str_sql + where1;
                            dsmove_mv = main.dbservice.oracle_exec_selectsql(str_sql_mv);
                            str_sql_con = str_sql + where2;
                            dsmove_con = main.dbservice.oracle_exec_selectsql(str_sql_con);
                        }
                        dataGridView2.DataSource = dsmove_mv.Tables[0];
                        dataGridView3.DataSource = dsmove_con.Tables[0];
                    }
                    else //分配到托盘批次
                    {
                        str_sql = " select a.*,a.confirm_qty_m as old_confirm_qty_m " +
                           "  from " + main.g_space + ".inv_move_detail a ," + main.g_space + ".inv_sku_pallet b" +
                                  " where a.inv_org=b.inv_org and a.consignor=b.consignor and a.moveout_location=b.location_code and a.batchno=b.batchno and a.moveout_pallet=b.pallet_no " +
                                  " and a.sku=b.sku  " +
                                  " and a.inv_org = '" + main.g_org + "' and a.move_no='" + dsmove_header.Tables[0].Rows[0]["move_no"].ToString().Trim() + "' and a.consignor='" + dsmove_header.Tables[0].Rows[0]["consignor"].ToString().Trim() + "'";

                        move_no_str = dsmove_header.Tables[0].Rows[0]["move_no"].ToString().Trim();
                        dsmove_mv = new DataSet();
                        dsmove_con = new DataSet();
                        //where1 = " and moveout_pallet='0' and batchno='0' and main_dist <> 'D' ";
                        where2 = " and a.move_status in ('1','2')  ";
                        str_update_sql = "select a.*,confirm_qty_m as old_confirm_qty_m,0.0 tmp_qty from " + main.g_space + ".inv_move_detail a where inv_org = '" + main.g_org + "' and move_no='" + dsmove_header.Tables[0].Rows[0]["move_no"].ToString().Trim() + "' and consignor='" + dsmove_header.Tables[0].Rows[0]["consignor"].ToString().Trim() + "'";                        
                        if (main.dbtype == "SQL")
                        {                            
                            str_sql_mv = str_sql + where1;
                            dsmove_mv = main.dbservice.Sql_exec_selectsql(str_sql_mv);
                            str_sql_con = str_sql + where2;
                            dsmove_con = main.dbservice.Sql_exec_selectsql(str_sql_con);

                        }
                        else
                        {
                            str_sql_mv = str_sql + where1;
                            dsmove_mv = main.dbservice.oracle_exec_selectsql(str_sql_mv);
                            str_sql_con = str_sql + where2;
                            dsmove_con = main.dbservice.oracle_exec_selectsql(str_sql_con);
                        }
                        dataGridView2.DataSource = dsmove_mv.Tables[0];
                        dataGridView3.DataSource = dsmove_con.Tables[0];
                    }
                }
                else
                {
                    this.cbx_h_consignor.Text = "";
                    this.tb_h_consignor_name.Text = "";
                    //this.cb_move_type.SelectedIndex =;
                   // this.cb_h_move_status.SelectedValue = tr["move_status"].ToString().Trim();
                    // this.cbx_h_move_reason.SelectedValue = Convert.ToInt32(tr["move_reason"].ToString().Trim());

                    this.tb_h_move_no.Text = "";
                    this.tb_h_memo.Text = "";
                    //comboBox2.SelectedValue = 00;
                    dataGridView2.DataSource = null;
                    dataGridView3.DataSource = null;
                }
            }
            catch (System.Exception ee)
            {

                MessageBox.Show(main.g_class.comm_getchangestring("Fail to Query", main.g_info_dataset) + "!" + ee.ToString());
            }

        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            //string str_sql = "";
            //string where1 = "";
            //string where2 = "";
            //where1 = " and moveout_pallet='0' and batchno='0' and main_dist <> 'D' ";
            //where2 = " and moveout_pallet<>'0' and batchno<>'0' and main_dist <> 'D' ";
            //move_no_str = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["move_no_h"].Value.ToString().Trim();
            //str_sql_where = "inv_org = '" + main.g_org + "' and consignor='" + dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["consignor"].Value.ToString().Trim() + "' and move_no='" + dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["move_no_h"].Value.ToString().Trim() + "'";
            ////取确认状态
            //g_str_status = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["move_status"].Value.ToString().Trim();
            //g_str_status = main.g_class.comm_getconversestring(g_str_status, main.g_info_dataset);
            //switch (g_str_status.Trim().ToLower())
            //{
            //    case "make":
            //        g_str_status = "0";
            //        break;
            //    case "part confirm":
            //        g_str_status = "1";
            //        break;
            //    case "confirm":
            //        g_str_status = "2";
            //        break;
            //    case "close":
            //        g_str_status = "3";
            //        break;
            //    default:
            //        g_str_status = "";
            //        break;
            //}
            //DataRow[] tr_header = dsmove_header.Tables[0].Select(str_sql_where);

            //if (tr_header.Length > 0)
            //{
            //    show(tr_header[0]);

            //    dsmove_mv = new DataSet();
            //    dsmove_con = new DataSet();
            //    str_sql = "select a.*,confirm_qty_m as old_confirm_qty_m from " + main.g_space + ".inv_move_detail a where " + str_sql_where;
            //    if (main.dbtype == "SQL")
            //    {

            //        str_sql_mv = str_sql + where1;
            //        dsmove_mv = main.dbservice.Sql_exec_selectsql(str_sql_mv);
            //        str_sql_con = str_sql + where2;
            //        dsmove_con = main.dbservice.Sql_exec_selectsql(str_sql_con);

            //    }
            //    else
            //    {
            //        str_sql_mv = str_sql + where1;
            //        dsmove_mv = main.dbservice.oracle_exec_selectsql(str_sql_mv);
            //        str_sql_con = str_sql + where2;
            //        dsmove_con = main.dbservice.oracle_exec_selectsql(str_sql_con);
            //    }
            //    dataGridView2.DataSource = dsmove_mv.Tables[0];

            //    dataGridView3.DataSource = dsmove_con.Tables[0];
            //}


        }

        private void bt_Direction_Click(object sender, EventArgs e)
        {
            if (tb_h_move_no.Text.Trim().Substring(0, 2).ToUpper() != "MV") //如果不是我们的单子，是金碟传来的单据
            {
                MessageBox.Show("此单据缺少移库库位!");
                return;
            }
            //取确认状态
            g_str_status = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["move_status"].Value.ToString().Trim();
            g_str_status = main.g_class.comm_getconversestring(g_str_status, main.g_info_dataset);
            switch (g_str_status.Trim().ToLower())
            {
                case "make":
                    g_str_status = "0";
                    break;
                case "part confirm":
                    g_str_status = "1";
                    break;
                case "confirm":
                    g_str_status = "2";
                    break;
                case "close":
                    g_str_status = "3";
                    break;
                default:
                    g_str_status = "";
                    break;
            }

            if (g_str_status == "3")
                return;
            for (int i = 0; i < dsmove_mv.Tables[0].Rows.Count; i++)
            {
                if (dsmove_mv.Tables[0].Rows[i]["confirm_qty_m"].ToString().Trim() == null || dsmove_mv.Tables[0].Rows[i]["confirm_qty_m"].ToString().Trim() == "")
                {
                    dsmove_mv.Tables[0].Rows[i]["confirm_qty_m"] = 0;
                }

                if ((Convert.ToDecimal(dsmove_mv.Tables[0].Rows[i]["move_qty_m"]) - Convert.ToDecimal(dsmove_mv.Tables[0].Rows[i]["confirm_qty_m"].ToString().Trim())) > 0)
                {
                    dsmove_mv.Tables[0].Rows[i]["tmp_qty_m"] = (Convert.ToDecimal(dsmove_mv.Tables[0].Rows[i]["move_qty_m"].ToString().Trim()) - Convert.ToDecimal(dsmove_mv.Tables[0].Rows[i]["confirm_qty_m"].ToString().Trim()));
                }

                else
                {
                    dsmove_mv.Tables[0].Rows[i]["tmp_qty_m"] = 0;
                }
            }
            g_str_oper = 2;
            this.bt_Confirm.Enabled = true;
            this.bt_Cancel.Enabled = true;
            this.bt_Close.Enabled = false;
        }

        private void bt_Cancel_Click(object sender, EventArgs e)
        {
            string str_sql = "";

            string where1 = "";
            string where2 = "";
            where1 = " and moveout_pallet='0' and batchno='0' and  move_status='0'and main_dist <> 'D'";
            where2 = " and moveout_pallet<>'0' and batchno<>'0'and main_dist <> 'D'";
            move_no_str = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["move_no_h"].Value.ToString().Trim();
            str_sql_where = "inv_org = '" + main.g_org + "' and consignor='" + dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["consignor"].Value.ToString().Trim() + "' and move_no='" + dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["move_no_h"].Value.ToString().Trim() + "'";
            DataRow[] tr_header = dsmove_header.Tables[0].Select(str_sql_where);

            if (tr_header.Length > 0)
            {
                show(tr_header[0]);

                dsmove_mv = new DataSet();
                dsmove_con = new DataSet();
                str_sql = "select a.*,confirm_qty_m as old_confirm_qty_m,0.0 temp_qty from " + main.g_space + ".inv_move_detail a where " + str_sql_where;
                if (main.dbtype == "SQL")
                {

                    str_sql_mv = str_sql + where1;
                    dsmove_mv = main.dbservice.Sql_exec_selectsql(str_sql_mv);
                    str_sql_con = str_sql + where2;
                    dsmove_con = main.dbservice.Sql_exec_selectsql(str_sql_con);
                }
                else
                {
                    str_sql_mv = str_sql + where1;
                    dsmove_mv = main.dbservice.oracle_exec_selectsql(str_sql_mv);
                    str_sql_con = str_sql + where2;
                    dsmove_con = main.dbservice.oracle_exec_selectsql(str_sql_con);
                }
                dataGridView2.DataSource = dsmove_mv.Tables[0];

                dataGridView3.DataSource = dsmove_con.Tables[0];
                g_str_oper = 0;
                this.bt_Close.Enabled = true;
                this.bt_Direction.Enabled = true;
                this.bt_Confirm.Enabled = false;
                this.bt_Cancel.Enabled = false;
            }


        }

        private void bt_Confirm_Click(object sender, EventArgs e)
        {
            if (g_str_status == "3")
                return;
            try
            {
                string aa = "";
                if (str_type == "0")
                {
                    if (main.dbtype == "SQL")
                        aa = main.dbservice.Sql_move_confirm(main.g_org, dsmove_mv, str_sql_mv, this.cbx_h_consignor.Text.Trim(), tb_h_move_no.Text.Trim(), main.g_user);
                    else
                        aa = main.dbservice.oracle_move_confirm(main.g_org, dsmove_mv, str_sql_mv, this.cbx_h_consignor.Text.Trim(), tb_h_move_no.Text.Trim(), main.g_user);
                    if (aa != "0")
                        MessageBox.Show(aa);
                }
                else
                {
                    
                    //dsmove_mv.Tables[0].Columns.Remove("lot_attribute1");
                    //dsmove_mv.Tables[0].Columns.Remove("lot_attribute2");
                    //dsmove_mv.Tables[0].Columns.Remove("lot_attribute3");
                    //dsmove_mv.Tables[0].Columns.Remove("lot_attribute4");
                    //dsmove_mv.Tables[0].Columns.Remove("lot_attribute5");
                    //dsmove_mv.Tables[0].Columns.Remove("lot_attribute6");
                    //dsmove_mv.Tables[0].Columns.Remove("lot_attribute7");
                    //dsmove_mv.Tables[0].Columns.Remove("lot_attribute8");
                    //dsmove_mv.Tables[0].Columns.Remove("lot_attribute9");
                    //dsmove_mv.Tables[0].Columns.Remove("lot_attribute10");
                    //dsmove_mv.Tables[0].Columns.Remove("lot_attribute11");
                    //dsmove_mv.Tables[0].Columns.Remove("lot_attribute12");
                    //dsmove_mv.Tables[0].Columns.Remove("lot_attribute13");
                    //dsmove_mv.Tables[0].Columns.Remove("lot_attribute14");
                    //dsmove_mv.Tables[0].Columns.Remove("lot_attribute15");
                
                    if (main.dbtype == "SQL")
                        aa = main.dbservice.Sql_move_confirm(main.g_org, dsmove_mv, str_update_sql, this.cbx_h_consignor.Text.Trim(), tb_h_move_no.Text.Trim(), main.g_user);
                    else
                        aa = main.dbservice.oracle_move_confirm(main.g_org, dsmove_mv, str_update_sql, this.cbx_h_consignor.Text.Trim(), tb_h_move_no.Text.Trim(), main.g_user);
                    if (aa != "0")
                        MessageBox.Show(aa);
                }

            }

            catch (System.Exception ee)
            {
                MessageBox.Show(main.g_class.comm_getchangestring("Fail to comfirm", main.g_info_dataset) + "!" + ee.ToString().Trim());
                Cursor.Current = Cursors.Default;
                return;
            }
            //刷新移库信息
            // btn_Query_Click(sender, new EventArgs());
            #region
            //string str_sql = "";
            //string where1 = "";
            //string where2 = "";
            //where1 = " and moveout_pallet='0' and batchno='0' and main_dist <> 'D' ";
            //where2 = " and moveout_pallet<>'0' and batchno<>'0' and main_dist <> 'D' ";
            //move_no_str = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["move_no_h"].Value.ToString().Trim();
            //str_sql_where = "inv_org = '" + main.g_org + "' and consignor='" + dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["consignor"].Value.ToString().Trim() + "' and move_no='" + dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["move_no_h"].Value.ToString().Trim() + "'";
            ////取确认状态
            //g_str_status = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["move_status"].Value.ToString().Trim();
            //g_str_status = main.g_class.comm_getconversestring(g_str_status, main.g_info_dataset);
            //switch (g_str_status.Trim().ToLower())
            //{
            //    case "make":
            //        g_str_status = "0";
            //        break;
            //    case "part confirm":
            //        g_str_status = "1";
            //        break;
            //    case "confirm":
            //        g_str_status = "2";
            //        break;
            //    case "close":
            //        g_str_status = "3";
            //        break;
            //    default:
            //        g_str_status = "";
            //        break;
            //}
            //DataRow[] tr_header = dsmove_header.Tables[0].Select(str_sql_where);

            //if (tr_header.Length > 0)
            //{
            //    show(tr_header[0]);

            //    dsmove_mv = new DataSet();
            //    dsmove_con = new DataSet();
            //    str_sql = "select a.*,confirm_qty_m as old_confirm_qty_m from " + main.g_space + ".inv_move_detail a where " + str_sql_where;
            //    if (main.dbtype == "SQL")
            //    {

            //        str_sql_mv = str_sql + where1;
            //        dsmove_mv = main.dbservice.Sql_exec_selectsql(str_sql_mv);
            //        str_sql_con = str_sql + where2;
            //        dsmove_con = main.dbservice.Sql_exec_selectsql(str_sql_con);

            //    }
            //    else
            //    {
            //        str_sql_mv = str_sql + where1;
            //        dsmove_mv = main.dbservice.oracle_exec_selectsql(str_sql_mv);
            //        str_sql_con = str_sql + where2;
            //        dsmove_con = main.dbservice.oracle_exec_selectsql(str_sql_con);
            //    }
            //    dataGridView2.DataSource = dsmove_mv.Tables[0];

            //    dataGridView3.DataSource = dsmove_con.Tables[0];
            //}
            #endregion
            g_str_oper = 0;
            tabControl1.SelectedIndex = 1;
            this.bt_Confirm.Enabled = false;
            this.bt_Cancel.Enabled = false;
            this.bt_Close.Enabled = true;
            //btn_Query_Click(sender, new EventArgs());
            dataGridView1_SelectionChanged(sender,new EventArgs());
        }

        private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (g_str_oper == 1)
            {
                tabControl1.SelectedIndex = 1;
                return;

            }
            else if (g_str_oper == 2)
            {
                if (bt_Confirm.Enabled == true)
                {
                    tabControl1.SelectedIndex = 0;
                }
            }
        }

        private void dataGridView3_DoubleClick(object sender, EventArgs e)
        {
            string str_name = "";
            if (g_str_oper == 1)
            {
                if (dataGridView3.CurrentRow != null)  //说明有选中的行有效
                {
                    str_name = dataGridView3.Columns[dataGridView3.CurrentCell.ColumnIndex].Name.ToString().Trim();
                    if (str_name == "from_warehouse")
                    {
                        //if (((DataTable)dataGridView3.DataSource).Rows[dataGridView3.CurrentRow.Index]["from_warehouse"].ToString().Trim() == "")
                        //{
                        w_inv013_warehouse frm = new w_inv013_warehouse();
                        frm.ShowDialog();
                        if (w_inv013_warehouse.s_warehouse.Trim() != "")
                        {
                            ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.CurrentRow.Index]["from_warehouse"] = w_inv013_warehouse.s_warehouse.Trim();
                        }
                        //}
                    }
                    if (str_name == "to_warehouse")
                    {
                        //if (((DataTable)dataGridView3.DataSource).Rows[dataGridView3.CurrentRow.Index]["to_warehouse"].ToString().Trim() == "")
                        //{
                        w_inv013_warehouse frm = new w_inv013_warehouse();
                        frm.ShowDialog();
                        if (w_inv013_warehouse.s_warehouse.Trim() != "")
                        {
                            ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.CurrentRow.Index]["to_warehouse"] = w_inv013_warehouse.s_warehouse.Trim();
                        }
                        //}
                    }
                    if (System.Convert.ToInt32(dataGridView3.Rows[dataGridView3.CurrentRow.Index].Cells["E_move_line_no"].Value.ToString().Trim()) == g_line_no)
                    {
                        //如果称入库位和移出库位不为空说明不是
                        //if (dataGridView3.Rows[dataGridView3.CurrentRow.Index].Cells["E_moveout_location"].Value.ToString().Trim() != "" && dataGridView3.Rows[dataGridView3.CurrentRow.Index].Cells["E_movein_location"].Value.ToString().Trim() != "")
                        //如果是MV开头的单子，是我们自己的单据，是有移出和称入库位的，按我们正常的方式操作
                        if (tb_h_move_no.Text.Trim().Substring(0, 2).ToUpper() == "MV")
                        {
                            if (str_name == "E_moveout_pallet" || str_name == "E_batchno")
                            {
                                dt_save.Clear();
                                DataRow drrow = dt_save.NewRow();

                                drrow["consignor"] = this.cbx_h_consignor.Text.Trim();
                                drrow["so_no"] = "";
                                drrow["so_line_no"] = "";
                                drrow["sku"] = (string)dataGridView3.Rows[dataGridView3.CurrentRow.Index].Cells["E_sku"].Value.ToString();
                                drrow["location_code"] = (string)dataGridView3.Rows[dataGridView3.CurrentRow.Index].Cells["E_moveout_location"].Value.ToString();
                                drrow["qty"] = "0";
                                drrow["n_ea_cubage"] = "0";
                                drrow["n_ea_gross"] = "0";
                                drrow["n_ea_net"] = "0";
                                //drrow["old_qty"] = (string)dataGridView3.Rows[dataGridView3.CurrentRow.Index].Cells["Old_confirm_qty_m"].Value.ToString();
                                drrow["old_qty"] = L_qty.ToString();
                                dt_save.Rows.Add(drrow);
                                w_inv013_loc w_inv013_loc = new w_inv013_loc();
                                w_inv013_loc.ShowDialog();
                                ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.CurrentRow.Index]["batchno"] = dt_save.Rows[0]["so_no"].ToString();
                                ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.CurrentRow.Index]["moveout_pallet"] = dt_save.Rows[0]["so_line_no"].ToString();
                                ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.CurrentRow.Index]["movein_pallet"] = dt_save.Rows[0]["so_line_no"].ToString();
                                ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.CurrentRow.Index]["confirm_cubage"] = Math.Round(System.Convert.ToDecimal(dt_save.Rows[0]["qty"].ToString().Trim()) * System.Convert.ToDecimal(dt_save.Rows[0]["n_ea_cubage"].ToString().Trim()), 4);
                                ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.CurrentRow.Index]["confirm_gross_weight"] = Math.Round(System.Convert.ToDecimal(dt_save.Rows[0]["qty"].ToString().Trim()) * System.Convert.ToDecimal(dt_save.Rows[0]["n_ea_gross"].ToString().Trim()), 4);
                                ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.CurrentRow.Index]["confirm_net_weight"] = Math.Round(System.Convert.ToDecimal(dt_save.Rows[0]["qty"].ToString().Trim()) * System.Convert.ToDecimal(dt_save.Rows[0]["n_ea_net"].ToString().Trim()), 4);
                                ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.CurrentRow.Index]["confirm_qty_m"] = dt_save.Rows[0]["qty"].ToString();
                                dataGridView3.Rows[dataGridView3.CurrentRow.Index].Cells["temp_qty"].Value = dt_save.Rows[0]["qty"].ToString();
                                ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.CurrentRow.Index]["confirm_qty_s"] = Math.Round(System.Convert.ToDecimal(dt_save.Rows[0]["qty"].ToString().Trim()) * System.Convert.ToDecimal(((DataTable)dataGridView3.DataSource).Rows[dataGridView3.CurrentRow.Index]["convert_modulus"]), 4);
                                ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.CurrentRow.Index]["old_confirm_qty_m"] = dt_save.Rows[0]["old_qty"].ToString();
                                g_round = 0;
                            }
                        }
                        //  如果不是MV开头的单子，是金碟传来的单据 是没有移出和移入库位的 要先选择库位
                        else
                        {
                            str_name = dataGridView3.Columns[dataGridView3.CurrentCell.ColumnIndex].Name.ToString().Trim();
                            if (str_name == "E_moveout_pallet" || str_name == "E_batchno" || str_name == "E_moveout_location")
                            {
                                dt_save.Clear();
                                DataRow drrow = dt_save.NewRow();

                                drrow["consignor"] = this.cbx_h_consignor.Text.Trim();
                                drrow["so_no"] = "";
                                drrow["so_line_no"] = "";
                                drrow["sku"] = (string)dataGridView3.Rows[dataGridView3.CurrentRow.Index].Cells["E_sku"].Value.ToString();
                                drrow["location_code"] = (string)dataGridView3.Rows[dataGridView3.CurrentRow.Index].Cells["E_moveout_location"].Value.ToString();
                                drrow["qty"] = "0";
                                drrow["n_ea_cubage"] = "0";
                                drrow["n_ea_gross"] = "0";
                                drrow["n_ea_net"] = "0";
                                //drrow["old_qty"] = (string)dataGridView3.Rows[dataGridView3.CurrentRow.Index].Cells["Old_confirm_qty_m"].Value.ToString();
                                drrow["old_qty"] = L_qty.ToString();
                                dt_save.Rows.Add(drrow);

                                w_inv013_loc w_inv013_loc = new w_inv013_loc();
                                w_inv013_loc.s_warehouse = dataGridView3.Rows[dataGridView3.CurrentRow.Index].Cells["from_warehouse"].Value.ToString().Trim();//传入仓库
                                w_inv013_loc.s_type = "out";
                                w_inv013_loc.s_lot = dataGridView3.Rows[dataGridView3.CurrentRow.Index].Cells["standby_4"].EditedFormattedValue.ToString().Trim();//传批次
                                w_inv013_loc.ShowDialog();
                                ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.CurrentRow.Index]["moveout_location"] = dt_save.Rows[0]["location_code"].ToString();
                                ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.CurrentRow.Index]["batchno"] = dt_save.Rows[0]["so_no"].ToString();
                                ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.CurrentRow.Index]["moveout_pallet"] = dt_save.Rows[0]["so_line_no"].ToString();
                                ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.CurrentRow.Index]["movein_pallet"] = dt_save.Rows[0]["so_line_no"].ToString();
                                ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.CurrentRow.Index]["confirm_cubage"] = Math.Round(System.Convert.ToDecimal(dt_save.Rows[0]["qty"].ToString().Trim()) * System.Convert.ToDecimal(dt_save.Rows[0]["n_ea_cubage"].ToString().Trim()), 4);
                                ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.CurrentRow.Index]["confirm_gross_weight"] = Math.Round(System.Convert.ToDecimal(dt_save.Rows[0]["qty"].ToString().Trim()) * System.Convert.ToDecimal(dt_save.Rows[0]["n_ea_gross"].ToString().Trim()), 4);
                                ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.CurrentRow.Index]["confirm_net_weight"] = Math.Round(System.Convert.ToDecimal(dt_save.Rows[0]["qty"].ToString().Trim()) * System.Convert.ToDecimal(dt_save.Rows[0]["n_ea_net"].ToString().Trim()), 4);
                                ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.CurrentRow.Index]["confirm_qty_m"] = dt_save.Rows[0]["qty"].ToString();
                                dataGridView3.Rows[dataGridView3.CurrentRow.Index].Cells["temp_qty"].Value = dt_save.Rows[0]["qty"].ToString();
                                ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.CurrentRow.Index]["confirm_qty_s"] = Math.Round(System.Convert.ToDecimal(dt_save.Rows[0]["qty"].ToString().Trim()) * System.Convert.ToDecimal(((DataTable)dataGridView3.DataSource).Rows[dataGridView3.CurrentRow.Index]["convert_modulus"]), 4);
                                ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.CurrentRow.Index]["Old_confirm_qty_m"] = dt_save.Rows[0]["old_qty"].ToString();
                                g_round = 0;
                                w_inv013_loc.s_warehouse = "";
                            }
                            else if (str_name == "E_movein_location")//选择移入库位
                            {
                                w_inv013_locat_list w_inv013_loc = new w_inv013_locat_list();
                                w_inv013_locat_list.s_warehouse = dataGridView3.Rows[dataGridView3.CurrentRow.Index].Cells["to_warehouse"].Value.ToString().Trim();//传入仓库
                                w_inv013_loc.ShowDialog();
                                ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.CurrentRow.Index]["movein_location"] = w_inv013_locat_list.str_location_code.Trim();
                            }
                        }
                    }

                }
            }

        }

        private void dataGridView3_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            string str_name;
            string sp_csgo, sp_move_no, p_sku, sp_loc, sp_bat, sp_in_pallet;
            int i_temp, sp_line_no, i_found;
            sp_csgo = cbx_h_consignor.Text.Trim();
            if (e.RowIndex != -1)  //说明有选中的行有效
            {
                i_temp = dataGridView3.CurrentRow.Index;
                str_name = dataGridView3.Columns[dataGridView3.CurrentCell.ColumnIndex].Name.ToString().Trim();
                if (str_name == "E_confirm_qty_m" || str_name == "E_movein_pallet")
                {
                    if (g_str_oper == 1 && g_round == 1) //说明是新增,只允许对新增行编辑
                    {
                        if (System.Convert.ToDecimal(dataGridView3.Rows[dataGridView3.RowCount - 1].Cells["E_confirm_qty_m"].EditedFormattedValue.ToString().Trim()) > System.Convert.ToDecimal(dt_save.Rows[0]["old_qty"])) //说明超过可用数量
                        {
                            MessageBox.Show(main.g_class.comm_getchangestring("The quantity of inputting more than available quantity", main.g_info_dataset) + ":" + dataGridView3.Rows[dataGridView3.RowCount - 1].Cells["Old_confirm_qty_m"].EditedFormattedValue.ToString().Trim());
                            dt_save.Rows[0]["qty"] = "0";
                            ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.RowCount - 1]["confirm_cubage"] = 0;
                            ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.RowCount - 1]["confirm_gross_weight"] = 0;
                            ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.RowCount - 1]["confirm_net_weight"] = 0;
                            dataGridView3.Rows[dataGridView3.CurrentRow.Index].Selected = false;
                            dataGridView3.Rows[dataGridView3.CurrentRow.Index].Selected = true;
                            return;
                        }
                        else
                        {
                            dt_save.Rows[0]["qty"] = System.Convert.ToString(Math.Round(System.Convert.ToDecimal(dataGridView3.Rows[dataGridView3.RowCount - 1].Cells["E_confirm_qty_m"].EditedFormattedValue.ToString().Trim()), 4));
                            ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.RowCount - 1]["confirm_cubage"] = Math.Round(System.Convert.ToDecimal(dt_save.Rows[0]["qty"].ToString().Trim()) * System.Convert.ToDecimal(dt_save.Rows[0]["n_ea_cubage"].ToString().Trim()), 4);
                            ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.RowCount - 1]["confirm_gross_weight"] = Math.Round(System.Convert.ToDecimal(dt_save.Rows[0]["qty"].ToString().Trim()) * System.Convert.ToDecimal(dt_save.Rows[0]["n_ea_gross"].ToString().Trim()), 4);
                            ((DataTable)dataGridView3.DataSource).Rows[dataGridView3.RowCount - 1]["confirm_net_weight"] = Math.Round(System.Convert.ToDecimal(dt_save.Rows[0]["qty"].ToString().Trim()) * System.Convert.ToDecimal(dt_save.Rows[0]["n_ea_net"].ToString().Trim()), 4);

                        }

                        dataGridView3.Rows[dataGridView3.CurrentRow.Index].Selected = false;
                        dataGridView3.Rows[dataGridView3.CurrentRow.Index].Selected = true;
                    }
                    else if (g_str_oper == 2)   //说明是修改
                    {
                        i_temp = dataGridView3.CurrentRow.Index;

                        sp_move_no = tb_h_move_no.Text.Trim();

                        sp_line_no = System.Convert.ToInt32(dataGridView3.Rows[i_temp].Cells["E_move_line_no"].EditedFormattedValue.ToString().Trim());
                        p_sku = (string)dataGridView3.Rows[i_temp].Cells["E_sku"].EditedFormattedValue.ToString().Trim();
                        sp_loc = (string)dataGridView3.Rows[i_temp].Cells["E_moveout_location"].EditedFormattedValue.ToString().Trim();
                        sp_bat = (string)dataGridView3.Rows[i_temp].Cells["E_batchno"].EditedFormattedValue.ToString().Trim();
                        sp_in_pallet = (string)dataGridView3.Rows[i_temp].Cells["E_movein_pallet"].EditedFormattedValue.ToString().Trim();
                        // sp_qty = dataGridView3.Rows[i_temp].Cells["E_confirm_qty_m"].EditedFormattedValue.ToString().Trim();
                        if (System.Convert.ToDecimal(dataGridView3.Rows[i_temp].Cells["E_confirm_qty_m"].EditedFormattedValue.ToString().Trim()) > System.Convert.ToDecimal(dataGridView3.Rows[i_temp].Cells["Old_confirm_qty_m"].EditedFormattedValue.ToString().Trim())) //说明超过可用数量
                        {
                            MessageBox.Show(main.g_class.comm_getchangestring("The quantity of inputting more than available quantity", main.g_info_dataset) + ":" + dataGridView3.Rows[i_temp].Cells["Old_confirm_qty_m"].EditedFormattedValue.ToString().Trim());
                            //寻找dt_save相应的行号，返回-1说明没有直接改dg_allocate
                            i_found = f_get_save_index(sp_csgo, sp_move_no, sp_line_no.ToString(), sp_loc);
                            if (i_found != -1) dt_save.Rows[i_found]["qty"] = "0";
                            i_found = f_get_table_index(sp_csgo, sp_move_no, sp_line_no.ToString(), sp_loc);
                            ((DataTable)dataGridView3.DataSource).Rows[i_found]["confirm_cubage"] = 0;
                            ((DataTable)dataGridView3.DataSource).Rows[i_found]["confirm_gross_weight"] = 0;
                            ((DataTable)dataGridView3.DataSource).Rows[i_found]["confirm_net_weight"] = 0;
                            dataGridView3.Rows[dataGridView3.CurrentRow.Index].Selected = false;
                            dataGridView3.Rows[dataGridView3.CurrentRow.Index].Selected = true;
                            return;
                        }
                        else //不超过
                        {


                            //寻找dt_save相应的行号，返回-1说明没有直接改dg_allocate
                            i_found = f_get_save_index(sp_csgo, sp_move_no, sp_line_no.ToString(), sp_loc);
                            if (i_found != -1)  //说明有信息,修改
                                modify.Rows[i_found]["qty"] = System.Convert.ToString(Math.Round(System.Convert.ToDecimal(dataGridView3.Rows[i_temp].Cells["E_confirm_qty_m"].EditedFormattedValue.ToString().Trim()), 4));
                            else //没有信息，新增
                            {
                                DataRow drrow = modify.NewRow();
                                drrow["old_qty"] = System.Convert.ToString(Math.Round(System.Convert.ToDecimal(dataGridView3.Rows[i_temp].Cells["Old_confirm_qty_m"].EditedFormattedValue.ToString().Trim()), 4));
                                drrow["qty"] = System.Convert.ToString(Math.Round(System.Convert.ToDecimal(dataGridView3.Rows[i_temp].Cells["E_confirm_qty_m"].EditedFormattedValue.ToString().Trim()), 4));
                                drrow["consignor"] = sp_csgo;
                                drrow["move_no"] = sp_move_no;
                                drrow["move_line_no"] = System.Convert.ToInt32(dataGridView3.Rows[i_temp].Cells["E_move_line_no"].EditedFormattedValue.ToString().Trim());
                                drrow["sku"] = System.Convert.ToString(dataGridView3.Rows[i_temp].Cells["E_sku"].EditedFormattedValue.ToString().Trim());
                                drrow["location_code"] = System.Convert.ToString(dataGridView3.Rows[i_temp].Cells["E_moveout_location"].EditedFormattedValue.ToString().Trim());
                                drrow["batch_no"] = System.Convert.ToString(dataGridView3.Rows[i_temp].Cells["E_batchno"].EditedFormattedValue.ToString().Trim());
                                drrow["pallet_no"] = System.Convert.ToString(dataGridView3.Rows[i_temp].Cells["E_moveout_pallet"].EditedFormattedValue.ToString().Trim());
                                drrow["in_pallet_no"] = System.Convert.ToString(dataGridView3.Rows[i_temp].Cells["E_movein_pallet"].EditedFormattedValue.ToString().Trim());
                                modify.Rows.Add(drrow);
                            }
                            i_found = f_get_table_index(sp_csgo, sp_move_no, sp_line_no.ToString(), sp_loc);
                            ((DataTable)dataGridView3.DataSource).Rows[i_found]["confirm_qty_m"] = Math.Round(System.Convert.ToDecimal(dataGridView3.Rows[i_temp].Cells["E_confirm_qty_m"].EditedFormattedValue.ToString().Trim()), 4);
                            ((DataTable)dataGridView3.DataSource).Rows[i_found]["confirm_qty_s"] = Math.Round(System.Convert.ToDecimal(dataGridView3.Rows[i_temp].Cells["E_confirm_qty_m"].EditedFormattedValue.ToString().Trim()) * (System.Convert.ToDecimal(dataGridView3.Rows[i_temp].Cells["E_confirm_qty_s"].EditedFormattedValue.ToString().Trim()) / System.Convert.ToDecimal(dataGridView3.Rows[i_temp].Cells["Old_confirm_qty_m"].EditedFormattedValue.ToString().Trim())), 4);
                            //((DataTable)dataGridView3.DataSource).Rows[i_found]["confirm_cubage"] = Math.Round(System.Convert.ToDecimal(dataGridView3.Rows[i_temp].Cells["E_confirm_qty_m"].EditedFormattedValue.ToString().Trim()) * (System.Convert.ToDecimal(dataGridView3.Rows[i_temp].Cells["E_confirm_cubage"].EditedFormattedValue.ToString().Trim()) / System.Convert.ToDecimal(dataGridView3.Rows[i_temp].Cells["Old_confirm_qty_m"].EditedFormattedValue.ToString().Trim())), 4);
                            //((DataTable)dataGridView3.DataSource).Rows[i_found]["confirm_gross_weight"] = Math.Round(System.Convert.ToDecimal(dataGridView3.Rows[i_temp].Cells["E_confirm_qty_m"].EditedFormattedValue.ToString().Trim()) * (System.Convert.ToDecimal(dataGridView3.Rows[i_temp].Cells["E_confirm_gross_weight"].EditedFormattedValue.ToString().Trim()) / System.Convert.ToDecimal(dataGridView3.Rows[i_temp].Cells["Old_confirm_qty_m"].EditedFormattedValue.ToString().Trim())), 4);
                            //((DataTable)dataGridView3.DataSource).Rows[i_found]["confirm_net_weight"] = Math.Round(System.Convert.ToDecimal(dataGridView3.Rows[i_temp].Cells["E_confirm_qty_m"].EditedFormattedValue.ToString().Trim()) * (System.Convert.ToDecimal(dataGridView3.Rows[i_temp].Cells["E_confirm_net_weight"].EditedFormattedValue.ToString().Trim()) / System.Convert.ToDecimal(dataGridView3.Rows[i_temp].Cells["Old_confirm_qty_m"].EditedFormattedValue.ToString().Trim())), 4);
                        }
                        dataGridView3.Rows[dataGridView3.CurrentRow.Index].Selected = false;
                        dataGridView3.Rows[dataGridView3.CurrentRow.Index].Selected = true;

                    }

                }
            }
        }
        private Int32 f_get_table_index(string str_con, string str_so, string str_line, string str_loc)
        {
            if (((DataTable)dataGridView3.DataSource).Rows.Count > 0) //说明有数据查找
            {
                int i;
                for (i = 0; i < ((DataTable)dataGridView3.DataSource).Rows.Count; i++)
                {
                    if (((DataTable)dataGridView3.DataSource).Rows[i]["consignor"].ToString().Trim() == str_con && ((DataTable)dataGridView3.DataSource).Rows[i]["move_no"].ToString().Trim() == str_so && ((DataTable)dataGridView3.DataSource).Rows[i]["move_line_no"].ToString().Trim() == str_line && ((DataTable)dataGridView3.DataSource).Rows[i]["moveout_location"].ToString().Trim() == str_loc)  //找到
                        return i;
                }
                return -1;
            }
            else
                return -1;
        }
        private Int32 f_get_save_index(string str_con, string move_no, string str_line, string str_loc)
        {
            if (dt_save.Rows.Count > 0) //说明有数据查找
            {
                int i;
                for (i = 0; i < dt_save.Rows.Count; i++)
                {
                    if (modify.Rows[i]["consignor"].ToString().Trim() == str_con && modify.Rows[i]["move_no"].ToString().Trim() == move_no && modify.Rows[i]["move_line_no"].ToString().Trim() == str_line && modify.Rows[i]["location_code"].ToString().Trim() == str_loc)  //找到
                        return i;
                }
                return -1;
            }
            else
                return -1;
        }
        private void btn_save_Click(object sender, EventArgs e)
        {
            string str_ren;
            str_ren = "";
            //判断是否有移出和移入库位如果没有就能保存
            if (dataGridView3.Rows.Count > 0)
            {
                for (int i = 0; i < dataGridView3.Rows.Count; i++)
                {
                    if (dataGridView3.Rows[i].Cells["E_moveout_location"].Value.ToString().Trim() == "")
                    {
                        MessageBox.Show("必须选择移出库位!");
                        return;
                    }
                    else if (dataGridView3.Rows[i].Cells["E_movein_location"].Value.ToString().Trim() == "")
                    {
                        MessageBox.Show("必须选择移入库位!");
                        return;
                    }
                }
            }
            Cursor.Current = Cursors.WaitCursor;
            if (g_str_oper == 1) //说明是新增
            {
                if (System.Convert.ToDecimal(dt_save.Rows[0]["qty"].ToString().Trim()) != 0)
                {
                    string s_consignor = cbx_h_consignor.Text.Trim();
                    string s_move_no = tb_h_move_no.Text.Trim();
                    int i_line = System.Convert.ToInt32(((DataTable)dataGridView3.DataSource).Rows[((DataTable)dataGridView3.DataSource).Rows.Count - 1]["move_line_no"]);
                    string s_outloc = (string)((DataTable)dataGridView3.DataSource).Rows[((DataTable)dataGridView3.DataSource).Rows.Count - 1]["moveout_location"];
                    string s_inloc = (string)((DataTable)dataGridView3.DataSource).Rows[((DataTable)dataGridView3.DataSource).Rows.Count - 1]["movein_location"];
                    string s_pallet = (string)((DataTable)dataGridView3.DataSource).Rows[((DataTable)dataGridView3.DataSource).Rows.Count - 1]["moveout_pallet"];
                    string s_inpallet = (string)((DataTable)dataGridView3.DataSource).Rows[((DataTable)dataGridView3.DataSource).Rows.Count - 1]["movein_pallet"];
                    string s_bat = (string)((DataTable)dataGridView3.DataSource).Rows[((DataTable)dataGridView3.DataSource).Rows.Count - 1]["batchno"];
                    string s_outware = (string)((DataTable)dataGridView3.DataSource).Rows[((DataTable)dataGridView3.DataSource).Rows.Count - 1]["from_warehouse"];
                    string s_inware = (string)((DataTable)dataGridView3.DataSource).Rows[((DataTable)dataGridView3.DataSource).Rows.Count - 1]["to_warehouse"];
                    decimal d_qty = Math.Round(System.Convert.ToDecimal(((DataTable)dataGridView3.DataSource).Rows[((DataTable)dataGridView3.DataSource).Rows.Count - 1]["confirm_qty_m"]), 4);
                    decimal d_pallet_qty;
                    //判断托盘是否已用
                    string str_sql, str_tray, s_skus;
                    DataSet dt_tray;
                    int d_temp;
                    s_skus = (string)dataGridView3.Rows[dataGridView3.CurrentRow.Index].Cells["E_sku"].EditedFormattedValue.ToString().Trim();

                    str_sql = "select pallet_flag from " + main.g_space + ".mst_sku where inv_org = '" + main.g_org + "' and consignor ='" + s_consignor + "' and sku = '" + s_skus + "' ";
                    try
                    {

                        if (main.dbtype == "SQL")
                            dt_tray = main.dbservice.Sql_exec_selectsql(str_sql);
                        else
                            dt_tray = main.dbservice.oracle_exec_selectsql(str_sql);

                    }
                    catch (System.Exception ee)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Fail to get pallet_flag", main.g_info_dataset) + "!" + ee.ToString());
                        return;
                    }
                    str_tray = dt_tray.Tables[0].Rows[0][0].ToString().Trim();
                    //如果是托盘管理，先要判断扫面的托盘号是否已经在库存中存在或者在为上架的记录存在，
                    if (str_tray == "1")
                    {
                        if (s_inpallet != "")
                        {
                            if (s_inpallet != "000000000000000")
                            {
                                if (main.dbtype == "SQL")
                                    str_sql = "select count(*) from " + main.g_space + ".inv_sku_pallet where inv_org = '" + main.g_org + "' and pallet_no = '" + s_inpallet + "' and location_code <> '" + s_outloc + "' and (stock_qty_m - isnull(freeze_qty_m,0)) > 0";
                                else
                                    str_sql = "select count(*) from " + main.g_space + ".inv_sku_pallet where inv_org = '" + main.g_org + "' and pallet_no = '" + s_inpallet + "' and location_code <> '" + s_outloc + "' and (stock_qty_m - nvl(freeze_qty_m,0)) > 0";
                                if (main.dbtype == "SQL")
                                    d_temp = main.dbservice.Sql_exec_selectint(str_sql);
                                else
                                    d_temp = main.dbservice.oracle_exec_selectint(str_sql);
                                if (d_temp > 0) //说明托盘不合法
                                {
                                    MessageBox.Show(main.g_class.comm_getchangestring("the pallet is illegimate", main.g_info_dataset) + "!");
                                    return;
                                }
                                else
                                {
                                    str_sql = "select count(*) from " + main.g_space + ".asn_putaway where inv_org = '" + main.g_org + "' and pallet_no = '" + s_inpallet + "' and putaway_status = '0'";
                                    if (main.dbtype == "SQL")
                                        d_temp = main.dbservice.Sql_exec_selectint(str_sql);
                                    else
                                        d_temp = main.dbservice.oracle_exec_selectint(str_sql);
                                    if (d_temp > 0)
                                    {
                                        MessageBox.Show(main.g_class.comm_getchangestring("the pallet is illegimate", main.g_info_dataset) + "!");
                                        return;
                                    }
                                }
                            }

                        }
                    }
                    //判断托盘数量
                    string s_sql;
                    DataSet dt_pallet;
                    if (main.dbtype == "SQL")
                        s_sql = "select sum(isnull(stock_qty_m,0)) as stock_qty_m  from " + main.g_space + ".inv_sku_pallet  where inv_org = '" + main.g_org + "' and consignor ='" + s_consignor + "' and location_code = '" + s_outloc + "' and  pallet_no  = '" + s_pallet + "' ";
                    else
                        s_sql = "select sum(nvl(stock_qty_m,0)) as stock_qty_m from " + main.g_space + ".inv_sku_pallet  where inv_org = '" + main.g_org + "' and consignor ='" + s_consignor + "' and location_code = '" + s_outloc + "' and pallet_no  = '" + s_pallet + "'  ";
                    try
                    {
                        if (main.dbtype == "SQL")
                            dt_pallet = main.dbservice.Sql_exec_selectsql(s_sql);
                        else
                            dt_pallet = main.dbservice.oracle_exec_selectsql(s_sql);

                    }
                    catch (System.Exception ee)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Fail to get pallet stock ", main.g_info_dataset) + "!" + ee.ToString());
                        return;
                    }
                    d_pallet_qty = Math.Round(System.Convert.ToDecimal(dt_pallet.Tables[0].Rows[0][0].ToString().Trim()), 4);
                    if (d_pallet_qty != d_qty && s_pallet == s_inpallet)
                        s_inpallet = "";
                    try
                    {
                        //Sql_exec_proc_moveadd(string s_consignor, string s_move_no, int i_line, string s_outloc, string s_inloc, string s_pallet, string s_bat, decimal d_qty, decimal d_pallet_qty, string s_user, string s_flag)   移库新增 
                        if (main.dbtype == "SQL")
                            main.dbservice.Sql_exec_proc_moveadd(main.g_org, s_consignor, s_move_no, i_line, s_outloc, s_inloc, s_pallet, s_inpallet, s_bat, d_qty, d_pallet_qty, s_outware, s_inware, main.g_user, "0");
                        else
                        {
                            if (s_inpallet == "")
                                s_inpallet = "temp";
                            main.dbservice.oracle_exec_proc_moveadd(main.g_org, s_consignor, s_move_no, i_line, s_outloc, s_inloc, s_pallet, s_inpallet, s_bat, d_qty, d_pallet_qty, s_outware, s_inware, main.g_user, "0");
                        }
                    }
                    catch (System.Exception ee)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Fail to comfirm", main.g_info_dataset) + "!" + str_ren + ee.ToString().Trim());
                        Cursor.Current = Cursors.Default;
                        return;
                    }
                }
                else
                {
                    MessageBox.Show(main.g_class.comm_getchangestring("The quantity can't be zero ", main.g_info_dataset) + "!");
                    Cursor.Current = Cursors.Default;
                    return;
                }
            }
            else if (g_str_oper == 2) //说明是修改
            {
                string str_outlocation, str_batchno, str_customer, str_skus, str_inloc, str_pack;
                decimal d_outqty;
                str_pack = dataGridView3.Rows[0].Cells["E_pack_code"].EditedFormattedValue.ToString().Trim();
                str_inloc = dataGridView3.Rows[0].Cells["E_movein_location"].EditedFormattedValue.ToString().Trim();
                //判断库位是否可修改

                //判断数量是否有为0的
                for (int i = 0; i < modify.Rows.Count; i++)
                {
                    str_outlocation = modify.Rows[i]["location_code"].ToString().Trim();
                    str_batchno = modify.Rows[i]["batch_no"].ToString().Trim();
                    str_customer = modify.Rows[i]["consignor"].ToString().Trim();
                    str_skus = modify.Rows[i]["sku"].ToString().Trim();
                    d_outqty = System.Convert.ToDecimal(modify.Rows[i]["old_qty"].ToString().Trim()) - System.Convert.ToDecimal(modify.Rows[i]["qty"].ToString().Trim());

                    string str_lssql, str_loc = "";
                    if (main.dbtype == "SQL")
                    {
                        str_lssql = "select isnull(max(location_flag),'0') from " + main.g_space + ".mst_location where inv_org = '" + main.g_org + "' and location_code = '" + str_inloc + "'";
                        str_lssql = main.dbservice.Sql_exec_selectstring(str_lssql);
                    }
                    else
                    {
                        str_lssql = "select nvl(max(location_flag),'0') from " + main.g_space + ".mst_location where inv_org = '" + main.g_org + "' and location_code = '" + str_inloc + "'";
                        str_lssql = main.dbservice.oracle_exec_selectstring(str_lssql);
                    }
                    if (str_lssql.Trim() == "0") //说明是正常库位,需要判断
                    {
                        try
                        {
                            if (main.dbtype == "SQL")
                            {
                                str_loc = main.dbservice.Sql_exec_proc_moveloc(main.g_org, str_customer, str_skus, str_inloc, str_outlocation, d_outqty, str_pack);
                            }
                            else
                            {
                                str_loc = main.dbservice.oracle_exec_proc_moveloc(main.g_org, str_customer, str_skus, str_inloc, str_outlocation, d_outqty, str_pack);
                            }

                        }
                        catch (System.Exception ee)
                        {
                            MessageBox.Show(main.g_class.comm_getchangestring("Fail to get location  Information ", main.g_info_dataset) + "!" + ee.ToString());
                            Cursor.Current = Cursors.Default;
                            return;
                        }
                        if (str_loc == "UNKNOWN")
                        {
                            MessageBox.Show(main.g_class.comm_getchangestring("Fail to get location  Information", main.g_info_dataset) + "!");
                            return;
                        }
                    }

                    if (System.Convert.ToDecimal(modify.Rows[i]["qty"].ToString().Trim()) == 0)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("The quantity can't be zero ", main.g_info_dataset) + "!");
                        Cursor.Current = Cursors.Default;
                        return;
                    }


                }
                try
                {
                    DataSet ds_modify = new DataSet();
                    ds_modify.Tables.Add(modify);
                    if (main.dbtype == "SQL")
                        main.dbservice.Sql_exec_proc_movemodify(main.g_org, ds_modify, main.g_user);
                    else
                        main.dbservice.oracle_exec_proc_movemodify(main.g_org, ds_modify, main.g_user);

                    ds_modify.Tables.Clear();
                }
                catch (System.Exception ee)
                {
                    MessageBox.Show(main.g_class.comm_getchangestring("Fail to modify information of moving confirmation ", main.g_info_dataset) + "!" + ee.ToString().Trim());
                    Cursor.Current = Cursors.Default;
                    return;
                }
            }
            for (int i = 0; i < dataGridView3.Columns.Count; i++)
                dataGridView3.Columns[i].SortMode = DataGridViewColumnSortMode.Automatic;
            g_str_oper = 0;
            g_line_no = 0;
            dataGridView3.EditMode = DataGridViewEditMode.EditProgrammatically;
            //刷新移库信息
            #region  /刷新移库信息

            //string str_sql1 = "";
            //string where1 = "";
            //string where2 = "";
            //where1 = " and moveout_pallet='0' and batchno='0' and main_dist <> 'D' ";
            //where2 = " and moveout_pallet<>'0' and batchno<>'0' and main_dist <> 'D' ";
            //move_no_str = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["move_no_h"].Value.ToString().Trim();
            //str_sql_where = "inv_org = '" + main.g_org + "' and consignor='" + dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["consignor"].Value.ToString().Trim() + "' and move_no='" + dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["move_no_h"].Value.ToString().Trim() + "'";
            ////取确认状态
            //g_str_status = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["move_status"].Value.ToString().Trim();
            //g_str_status = main.g_class.comm_getconversestring(g_str_status, main.g_info_dataset);
            //switch (g_str_status.Trim().ToLower())
            //{
            //    case "make":
            //        g_str_status = "0";
            //        break;
            //    case "part confirm":
            //        g_str_status = "1";
            //        break;
            //    case "confirm":
            //        g_str_status = "2";
            //        break;
            //    case "close":
            //        g_str_status = "3";
            //        break;
            //    default:
            //        g_str_status = "";
            //        break;
            //}
            //DataRow[] tr_header = dsmove_header.Tables[0].Select(str_sql_where);

            //if (tr_header.Length > 0)
            //{
            //    show(tr_header[0]);

            //    dsmove_mv = new DataSet();
            //    dsmove_con = new DataSet();
            //    str_sql1 = "select a.*,confirm_qty_m as old_confirm_qty_m from " + main.g_space + ".inv_move_detail a where " + str_sql_where;
            //    if (main.dbtype == "SQL")
            //    {

            //        str_sql_mv = str_sql1 + where1;
            //        dsmove_mv = main.dbservice.Sql_exec_selectsql(str_sql_mv);
            //        str_sql_con = str_sql1 + where2;
            //        dsmove_con = main.dbservice.Sql_exec_selectsql(str_sql_con);

            //    }
            //    else
            //    {
            //        str_sql_mv = str_sql1 + where1;
            //        dsmove_mv = main.dbservice.oracle_exec_selectsql(str_sql_mv);
            //        str_sql_con = str_sql1 + where2;
            //        dsmove_con = main.dbservice.oracle_exec_selectsql(str_sql_con);
            //    }
            //    dataGridView2.DataSource = dsmove_mv.Tables[0];

            //    dataGridView3.DataSource = dsmove_con.Tables[0];
            //}

            #endregion

            this.btn_modi.Enabled = true;
            this.btn_del.Enabled = true;
            this.btn_save.Enabled = false;
            this.btn_cancel.Enabled = false;
            //btn_Query_Click(sender, new EventArgs());
            dataGridView1_SelectionChanged(sender, new EventArgs());
        }

        private void bt_Close_Click(object sender, EventArgs e)
        {
            if (cbx_h_consignor.Text != "" && tb_h_move_no.Text.Trim() != "")
            {
                try
                {
                    if (main.dbtype == "SQL")
                        main.dbservice.Sql_exec_proc_moveclose(main.g_org, cbx_h_consignor.Text.Trim(), tb_h_move_no.Text.Trim(), main.g_user);
                    else
                        main.dbservice.oracle_exec_proc_moveclose(main.g_org, cbx_h_consignor.Text.Trim(), tb_h_move_no.Text.Trim(), main.g_user);
                }
                catch (System.Exception ee)
                {
                    MessageBox.Show(main.g_class.comm_getchangestring("Fail to close moving bill", main.g_info_dataset) + "!" + ee.ToString().Trim());
                    Cursor.Current = Cursors.Default;
                    return;
                }
            }
        }


        private void bt_Close_Click_1(object sender, EventArgs e)
        {
            if (cbx_h_consignor.Text != "" && tb_h_move_no.Text.Trim() != "")
            {
                try
                {
                    if (main.dbtype == "SQL")
                        main.dbservice.Sql_exec_proc_moveclose(main.g_org, cbx_h_consignor.Text.Trim(), tb_h_move_no.Text.Trim(), main.g_user);
                    else
                        main.dbservice.oracle_exec_proc_moveclose(main.g_org, cbx_h_consignor.Text.Trim(), tb_h_move_no.Text.Trim(), main.g_user);
                }
                catch (System.Exception ee)
                {
                    MessageBox.Show(main.g_class.comm_getchangestring("Fail to close moving bill", main.g_info_dataset) + "!" + ee.ToString().Trim());
                    Cursor.Current = Cursors.Default;
                    return;
                }
                btn_Query_Click(sender, new EventArgs());
            }
        }

        private void dataGridView2_DoubleClick(object sender, EventArgs e)
        {
            if (str_type == "1")
            {
                return;
            }
            //取确认状态
            g_str_status = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["move_status"].Value.ToString().Trim();
            g_str_status = main.g_class.comm_getconversestring(g_str_status, main.g_info_dataset);
            switch (g_str_status.Trim().ToLower())
            {
                case "make":
                    g_str_status = "0";
                    break;
                case "part confirm":
                    g_str_status = "1";
                    break;
                case "confirm":
                    g_str_status = "2";
                    break;
                case "closed":
                    g_str_status = "3";
                    break;
                default:
                    g_str_status = "";
                    break;
            }

            if (g_str_status == "3" || g_str_status == "2")
                return;
            if (dataGridView2.CurrentRow.Index > -1)
            {
                if (dataGridView2.Rows[dataGridView2.CurrentRow.Index].Cells["confirm_qty_m"].Value.ToString() == "")
                    dataGridView2.Rows[dataGridView2.CurrentRow.Index].Cells["confirm_qty_m"].Value = 0;
                if (dataGridView2.Rows[dataGridView2.CurrentRow.Index].Cells["move_qty_m"].Value.ToString() == "")
                    dataGridView2.Rows[dataGridView2.CurrentRow.Index].Cells["move_qty_m"].Value = 0;
                if ((Convert.ToDecimal(dataGridView2.Rows[dataGridView2.CurrentRow.Index].Cells["move_qty_m"].Value) - Convert.ToDecimal(dataGridView2.Rows[dataGridView2.CurrentRow.Index].Cells["confirm_qty_m"].Value)) > 0)
                {
                    if (dataGridView2.Rows[dataGridView2.CurrentRow.Index].Cells["confirm_qty_m"].Value.ToString().Trim() == "")
                        L_qty = Math.Round(Convert.ToDecimal(dataGridView2.Rows[dataGridView2.CurrentRow.Index].Cells["move_qty_m"].Value.ToString().Trim()), 4);
                    else
                        L_qty = System.Convert.ToDecimal(Math.Round((Convert.ToDecimal(dataGridView2.Rows[dataGridView2.CurrentRow.Index].Cells["move_qty_m"].Value) - Convert.ToDecimal(dataGridView2.Rows[dataGridView2.CurrentRow.Index].Cells["confirm_qty_m"].Value)), 4));

                    DataRow[] tr1 = dsmove_mv.Tables[0].Select("move_line_no=" + dataGridView2.Rows[dataGridView2.CurrentRow.Index].Cells["move_line_no"].Value);
                    g_line_no = System.Convert.ToInt32(dataGridView2.Rows[dataGridView2.CurrentRow.Index].Cells["move_line_no"].Value.ToString().Trim());
                    DataRow ar = dsmove_con.Tables[0].NewRow();
                    for (int i = 0; i < dsmove_con.Tables[0].Columns.Count; i++)
                    {
                        ar[i] = tr1[0][i];
                    }

                    dsmove_con.Tables[0].Rows.Add(ar);
                    dataGridView2.Rows.Remove(dataGridView2.Rows[dataGridView2.CurrentRow.Index]);
                    tabControl1.SelectedIndex = 1;
                    g_str_oper = 1;
                    dataGridView3.DataSource = dsmove_con.Tables[0];
                    dataGridView3.Rows[dataGridView3.CurrentRow.Index].Selected = false;
                    dataGridView3.Rows[dataGridView3.RowCount - 1].Selected = true;
                    this.btn_modi.Enabled = false;
                    this.btn_del.Enabled = false;
                    this.btn_save.Enabled = true;
                    this.btn_cancel.Enabled = true;

                }


            }
        }

        private void dataGridView2_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            int i_temp;
            string str_name;
            if (e.RowIndex != -1)
            {
                i_temp = dataGridView2.CurrentRow.Index;
                str_name = dataGridView2.Columns[dataGridView2.CurrentCell.ColumnIndex].Name.ToString().Trim();
                if (str_name == "tmp_qty_m")
                {
                    if (dataGridView2.Rows[e.RowIndex].Cells["confirm_qty_s"].Value.ToString() == "")
                        dataGridView2.Rows[e.RowIndex].Cells["confirm_qty_s"].Value = 0;
                    if (dataGridView2.Rows[e.RowIndex].Cells["tmp_qty_m"].Value.ToString() == "")
                        dataGridView2.Rows[e.RowIndex].Cells["tmp_qty_m"].Value = 0;
                    if (dataGridView2.Rows[e.RowIndex].Cells["move_qty_m"].Value.ToString() == "")
                        dataGridView2.Rows[e.RowIndex].Cells["move_qty_m"].Value = 0;
                    if (Convert.ToDecimal(dataGridView2.Rows[e.RowIndex].Cells["tmp_qty_m"].Value) < 0 || Convert.ToDecimal(dataGridView2.Rows[e.RowIndex].Cells["tmp_qty_m"].Value) > (Convert.ToDecimal(dataGridView2.Rows[e.RowIndex].Cells["move_qty_m"].Value) - Convert.ToDecimal(dataGridView2.Rows[e.RowIndex].Cells["confirm_qty_s"].Value)))
                    {
                        dataGridView2.Rows[e.RowIndex].Cells["tmp_qty_m"].Value = 0;
                    }
                    this.bt_Confirm.Enabled = true;
                    this.bt_Cancel.Enabled = true;
                    this.bt_Close.Enabled = false;
                    g_str_oper = 1;
                }
            }
        }

        private void dataGridView2_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            string str_name;
            if (e.RowIndex != -1)  //说明有选中的行有效
            {
                str_name = dataGridView2.Columns[dataGridView2.CurrentCell.ColumnIndex].Name.ToString().Trim();

                if (str_name == "tmp_qty_m") //说明是新增行，编辑
                {
                    dataGridView2.EditMode = DataGridViewEditMode.EditOnKeystroke;
                }
                else //不是新增行不能编辑
                {
                    dataGridView2.EditMode = DataGridViewEditMode.EditProgrammatically;
                }
            }
        }

        private void btn_modi_Click_1(object sender, EventArgs e)
        {
            //取确认状态
            g_str_status = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["move_status"].Value.ToString().Trim();
            g_str_status = main.g_class.comm_getconversestring(g_str_status, main.g_info_dataset);
            switch (g_str_status.Trim().ToLower())
            {
                case "make":
                    g_str_status = "0";
                    break;
                case "part confirm":
                    g_str_status = "1";
                    break;
                case "confirm":
                    g_str_status = "2";
                    break;
                case "close":
                    g_str_status = "3";
                    break;
                default:
                    g_str_status = "";
                    break;
            }

            if (g_str_status == "3")
                return;
            dt_save.Rows.Clear();
            tabControl1.SelectedIndex = 1;
            this.btn_modi.Enabled = false;
            this.btn_del.Enabled = false;
            this.btn_save.Enabled = true;
            this.btn_cancel.Enabled = true;

            g_str_oper = 2;
        }

        private void dataGridView3_CellClick(object sender, DataGridViewCellEventArgs e)
        {

            if (g_str_oper == 1)
            {
                string str_name;
                if (e.RowIndex != -1)  //说明有选中的行有效
                {
                    if (System.Convert.ToInt32(dataGridView3.Rows[dataGridView3.CurrentRow.Index].Cells["E_move_line_no"].Value.ToString().Trim()) == g_line_no)
                    {
                        str_name = dataGridView3.Columns[dataGridView3.CurrentCell.ColumnIndex].Name.ToString().Trim();

                        if (str_name == "E_confirm_qty_m" || str_name == "E_movein_pallet") //说明是新增行，编辑
                        {
                            dataGridView3.EditMode = DataGridViewEditMode.EditOnKeystroke;
                        }
                        else //不是新增行不能编辑
                        {
                            dataGridView3.EditMode = DataGridViewEditMode.EditProgrammatically;
                        }
                    }
                }
            }
            if (g_str_oper == 2)
            {
                string str_name;
                if (e.RowIndex != -1)  //说明有选中的行有效
                {
                    str_name = dataGridView3.Columns[dataGridView3.CurrentCell.ColumnIndex].Name.ToString().Trim();

                    if (str_name == "E_confirm_qty_m") //说明是修改行，编辑
                    {
                        dataGridView3.EditMode = DataGridViewEditMode.EditOnKeystroke;
                    }
                    else //不是修改行不能编辑
                    {
                        dataGridView3.EditMode = DataGridViewEditMode.EditProgrammatically;
                    }
                }
            }
        }

        private void btn_del_Click_1(object sender, EventArgs e)
        {
            string sp_csgo, sp_move_no, p_sku, sp_loc, sp_bat, sp_pallet, str_inloc, str_pack;
            decimal d_qty;
            int sp_line_no;
            int i_temp;
            //取确认状态
            g_str_status = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["move_status"].Value.ToString().Trim();
            g_str_status = main.g_class.comm_getconversestring(g_str_status, main.g_info_dataset);
            switch (g_str_status.Trim().ToLower())
            {
                case "make":
                    g_str_status = "0";
                    break;
                case "part confirm":
                    g_str_status = "1";
                    break;
                case "confirm":
                    g_str_status = "2";
                    break;
                case "close":
                    g_str_status = "3";
                    break;
                default:
                    g_str_status = "";
                    break;
            }

            if (g_str_status == "3")
                return;
            if (dataGridView3.CurrentRow != null)  //说明选择了行号
            {
                i_temp = dataGridView3.CurrentRow.Index;
                sp_csgo = cbx_h_consignor.Text.Trim();
                sp_move_no = tb_h_move_no.Text.Trim();
                sp_line_no = System.Convert.ToInt32(dataGridView3.Rows[i_temp].Cells["E_move_line_no"].EditedFormattedValue.ToString().Trim());
                p_sku = (string)dataGridView3.Rows[i_temp].Cells["E_sku"].EditedFormattedValue.ToString().Trim();
                sp_loc = (string)dataGridView3.Rows[i_temp].Cells["E_moveout_location"].EditedFormattedValue.ToString().Trim();
                sp_bat = (string)dataGridView3.Rows[i_temp].Cells["E_batchno"].EditedFormattedValue.ToString().Trim();
                sp_pallet = (string)dataGridView3.Rows[i_temp].Cells["E_moveout_pallet"].EditedFormattedValue.ToString().Trim();
                str_inloc = (string)dataGridView3.Rows[i_temp].Cells["E_movein_location"].EditedFormattedValue.ToString().Trim();
                str_pack = (string)dataGridView3.Rows[i_temp].Cells["E_pack_code"].EditedFormattedValue.ToString().Trim();
                d_qty = System.Convert.ToDecimal(dataGridView3.Rows[i_temp].Cells["E_confirm_qty_m"].EditedFormattedValue.ToString().Trim());

                //判断库位是否合法
                string str_loc = "";
                try
                {
                    if (main.dbtype == "SQL")
                    {
                        str_loc = main.dbservice.Sql_exec_proc_moveloc(main.g_org, sp_csgo, p_sku, str_inloc, sp_loc, d_qty, str_pack);
                    }
                    else
                    {
                        str_loc = main.dbservice.oracle_exec_proc_moveloc(main.g_org, sp_csgo, p_sku, str_inloc, sp_loc, d_qty, str_pack);
                    }

                }
                catch (System.Exception ee)
                {
                    MessageBox.Show(main.g_class.comm_getchangestring("Fail to get location  Information ", main.g_info_dataset) + " !" + ee.ToString());
                    Cursor.Current = Cursors.Default;
                    return;
                }
                if (str_loc == "UNKNOWN")
                {
                    MessageBox.Show(main.g_class.comm_getchangestring("Fail to get location  Information ", main.g_info_dataset) + " !");
                    return;
                }

            }
            else
                return;
            if (MessageBox.Show(main.g_class.comm_getchangestring("Are you sure to delete , information", main.g_info_dataset) + "?", main.g_class.comm_getchangestring("Information", main.g_info_dataset), MessageBoxButtons.OKCancel) == DialogResult.OK)
            {
                Cursor.Current = Cursors.WaitCursor;
                try
                {
                    if (main.dbtype == "SQL")
                        main.dbservice.Sql_exec_proc_movedel(main.g_org, sp_csgo, sp_move_no, sp_line_no, p_sku, sp_loc, sp_bat, sp_pallet, main.g_user);
                    else
                        main.dbservice.oracle_exec_proc_movedel(main.g_org, sp_csgo, sp_move_no, sp_line_no, p_sku, sp_loc, sp_bat, sp_pallet, main.g_user);

                }
                catch (System.Exception ee)
                {
                    MessageBox.Show(main.g_class.comm_getchangestring("Fail to delete", main.g_info_dataset) + "!" + ee.ToString().Trim());
                }
                Cursor.Current = Cursors.Default;
            }
            //刷新移库信息
           // btn_Query_Click(sender, new EventArgs());
            dataGridView1_SelectionChanged(sender, new EventArgs());
        }

        private void btn_cancel_Click(object sender, EventArgs e)
        {
            g_str_oper = 0;
            dataGridView3.EditMode = DataGridViewEditMode.EditProgrammatically;
            //刷新移库信息
            //btn_Query_Click(sender, new EventArgs());
            #region  /刷新移库信息

            string str_sql1 = "";
            string where1 = "";
            string where2 = "";
            where1 = " and moveout_pallet='0' and batchno='0' and main_dist <> 'D' ";
            where2 = " and moveout_pallet<>'0' and batchno<>'0' and main_dist <> 'D' ";
            move_no_str = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["move_no_h"].Value.ToString().Trim();
            str_sql_where = "inv_org = '" + main.g_org + "' and consignor='" + dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["consignor"].Value.ToString().Trim() + "' and move_no='" + dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["move_no_h"].Value.ToString().Trim() + "'";
            //取确认状态
            g_str_status = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["move_status"].Value.ToString().Trim();
            g_str_status = main.g_class.comm_getconversestring(g_str_status, main.g_info_dataset);
            switch (g_str_status.Trim().ToLower())
            {
                case "make":
                    g_str_status = "0";
                    break;
                case "part confirm":
                    g_str_status = "1";
                    break;
                case "confirm":
                    g_str_status = "2";
                    break;
                case "close":
                    g_str_status = "3";
                    break;
                default:
                    g_str_status = "";
                    break;
            }
            DataRow[] tr_header = dsmove_header.Tables[0].Select(str_sql_where);

            if (tr_header.Length > 0)
            {
                show(tr_header[0]);

                dsmove_mv = new DataSet();
                dsmove_con = new DataSet();
                str_sql1 = "select a.*,confirm_qty_m as old_confirm_qty_m from " + main.g_space + ".inv_move_detail a where " + str_sql_where;
                if (main.dbtype == "SQL")
                {

                    str_sql_mv = str_sql1 + where1;
                    dsmove_mv = main.dbservice.Sql_exec_selectsql(str_sql_mv);
                    str_sql_con = str_sql1 + where2;
                    dsmove_con = main.dbservice.Sql_exec_selectsql(str_sql_con);

                }
                else
                {
                    str_sql_mv = str_sql1 + where1;
                    dsmove_mv = main.dbservice.oracle_exec_selectsql(str_sql_mv);
                    str_sql_con = str_sql1 + where2;
                    dsmove_con = main.dbservice.oracle_exec_selectsql(str_sql_con);
                }
                dataGridView2.DataSource = dsmove_mv.Tables[0];

                dataGridView3.DataSource = dsmove_con.Tables[0];
            }

            #endregion
            this.btn_modi.Enabled = true;
            this.btn_del.Enabled = true;
            this.btn_save.Enabled = false;
            this.btn_cancel.Enabled = false;
        }

        private void w_inv013_Load(object sender, EventArgs e)
        {

            int i_cbx = 0;
            ArrayList al_cbx = new ArrayList();
            modify = new DataTable();

            modify.Columns.Add("old_qty");
            modify.Columns.Add("qty");
            modify.Columns.Add("consignor");
            modify.Columns.Add("move_no");
            modify.Columns.Add("move_line_no");
            modify.Columns.Add("sku");
            modify.Columns.Add("location_code");
            modify.Columns.Add("batch_no");
            modify.Columns.Add("pallet_no");
            modify.Columns.Add("in_pallet_no");

            dt_save = new DataTable();
            dt_save.Columns.Add("consignor");
            dt_save.Columns.Add("so_no");
            dt_save.Columns.Add("so_line_no");
            dt_save.Columns.Add("sku");
            dt_save.Columns.Add("location_code");
            dt_save.Columns.Add("qty");
            dt_save.Columns.Add("n_ea_cubage");
            dt_save.Columns.Add("n_ea_gross");
            dt_save.Columns.Add("n_ea_net");
            //当新增的时候old_qty 如果库存可用数量大于缺货数量则是缺货数量 ，否则是库存可用数量 ，修改就是原计划数量
            dt_save.Columns.Add("old_qty");

            //当新增的时候old_qty 如果库存可用数量大于缺货数量则是缺货数量 ，否则是库存可用数量 ，修改就是原计划数量

            try
            {
                dscustomer = new DataSet();

                dscustomer = main.g_class.comm_get_consignor();
                cb_consignor.DataSource = dscustomer.Tables[0];
                cb_consignor.ValueMember = "consignor";
                cb_consignor.DisplayMember = "consignor";

                //i_cbx = cb_q_status.Items.Count;
                //al_cbx.Clear();
                //if (i_cbx > 0)
                //{
                //    for (int i = 0; i < i_cbx; i++)
                //    {
                //        if (cb_move_type.Items[i].ToString().Trim() != "")
                //            al_cbx.Add(main.g_class.comm_getchangestring(cb_move_type.Items[i].ToString().Trim(), main.g_info_dataset));
                //    }
                //    //清除cbx_bookstatus
                //    cb_move_type.Items.Clear();
                //    //在加入
                //    i_cbx = al_cbx.Count;
                //    for (int i = 0; i < i_cbx; i++)
                //    {
                //        cb_move_type.Items.Add(al_cbx[i]);
                //    }
                //    //出来在加上空值
                //    //cbx_bookstatus.Items.Add("");
                //}
                i_cbx = cb_h_move_status.Items.Count;
                al_cbx.Clear();
                if (i_cbx > 0)
                {
                    for (int i = 0; i < i_cbx; i++)
                    {
                        if (cb_h_move_status.Items[i].ToString().Trim() != "")
                            al_cbx.Add(main.g_class.comm_getchangestring(cb_h_move_status.Items[i].ToString().Trim(), main.g_info_dataset));
                    }
                    //清除cbx_bookstatus
                    cb_h_move_status.Items.Clear();
                    //在加入
                    i_cbx = al_cbx.Count;
                    for (int i = 0; i < i_cbx; i++)
                    {
                        cb_h_move_status.Items.Add(al_cbx[i]);
                    }
                    //出来在加上空值
                    //cbx_bookstatus.Items.Add("");
                }
                main.g_class.comm_changeControl(this, main.g_win_dataset);
                main.g_class.comm_changeCbxContent(cb_q_status, main.g_info_dataset, '1');
                main.g_class.comm_changeCbxContent(cb_h_move_status, main.g_info_dataset, '0');
                main.g_class.comm_changeCbxContent(cb_move_type, main.g_info_dataset, '0');

                g_str_oper = 0;
                dataGridView3.EditMode = DataGridViewEditMode.EditProgrammatically;
                dataGridView2.EditMode = DataGridViewEditMode.EditProgrammatically;
                dataGridView1.EditMode = DataGridViewEditMode.EditProgrammatically;
                this.btn_modi.Enabled = true;
                this.btn_del.Enabled = true;
                this.btn_save.Enabled = false;
                this.btn_cancel.Enabled = false;
                cb_q_status.SelectedIndex = 0;

            }
            catch (System.Exception ee)
            {
                MessageBox.Show(main.g_class.comm_getchangestring("Fail to get Consignor's Information!", main.g_info_dataset) + "!" + ee.ToString());
                return;
            }
            //获取分配是到库位还是到批次
            try
            {

                if (main.dbtype == "SQL")
                {
                    string str_sql2 = "select ltrim(rtrim(isnull(max(id_data),'0')))  from " + main.g_space + ".Sys_Parameter where inv_org = '" + main.g_org + "' and id = 8201";
                    str_type = main.dbservice.Sql_exec_selectstring(str_sql2).Trim();
                }
                else
                {
                    string str_sql2 = "select trim(nvl(max(id_data),'0'))  from " + main.g_space + ".Sys_Parameter where inv_org = '" + main.g_org + "' and id = 8201";
                    str_type = main.dbservice.oracle_exec_selectstring(str_sql2).Trim();
                }
            }
            catch (System.Exception ee)
            {
                MessageBox.Show(ee.ToString());
            }
            //对日期控件Format
            dtp_made_time.CustomFormat = "yyyy.MM.dd";
            dtp_made_time.Format = DateTimePickerFormat.Custom;
            dtp_made_time_end.CustomFormat = "yyyy.MM.dd";
            dtp_made_time_end.Format = DateTimePickerFormat.Custom;
            dtp_made_time.Value = System.Convert.ToDateTime(DateTime.Now.AddDays(-3).ToString("yyyy.MM.dd").Trim());
            dtp_made_time_end.Value = System.Convert.ToDateTime(DateTime.Now.ToString("yyyy.MM.dd").Trim());
            //获取按钮权限

            string str_right;

            str_right = main.g_class.comm_getright("w_inv013", main.g_right_dataset);

            //新增
            if (str_right.Substring(0, 1) == "0")
            {
                bt_Direction.Visible = false;
            }
            else
            {
                bt_Direction.Visible = true;
            }
            //修改
            if (str_right.Substring(1, 1) == "0")
            {
                btn_modi.Visible = false;
            }
            else
            {
                btn_modi.Visible = true;
            }
            //删除
            if (str_right.Substring(2, 1) == "0")
            {
                btn_del.Visible = false;
            }
            else
            {
                btn_del.Visible = true;
            }
            //保存，取消
            if (str_right.Substring(3, 1) == "0")
            {
                btn_save.Visible = false;
                btn_cancel.Visible = false;
            }
            else
            {
                btn_save.Visible = true;
                btn_cancel.Visible = true;
            }

            //确认，取消
            if (str_right.Substring(4, 1) == "0")
            {
                bt_Confirm.Visible = false;
                bt_Cancel.Visible = false;
            }
            else
            {
                bt_Confirm.Visible = true;
                bt_Cancel.Visible = true;
            }
            //关闭
            if (str_right.Substring(5, 1) == "0")
            {
                bt_Close.Visible = false;
            }
            else
            {
                bt_Close.Visible = true;
            }
            //初始化交易类型
            try
            {
                DataSet f_ds, ds_move;
                f_ds = main.g_class.comm_get_dictionary("move_trans");
                //进行语言转换
                int i_ds;
                i_ds = f_ds.Tables[0].Rows.Count;
                if (i_ds > 0)
                {
                    for (int i = 0; i < i_ds; i++)
                    {
                        f_ds.Tables[0].Rows[i]["move_trans"] = main.g_class.comm_getchangestring(f_ds.Tables[0].Rows[i]["move_trans"].ToString().Trim(), main.g_info_dataset);
                    }
                }
                //ds_check = f_ds.Copy();
                //DataSet newf_ds = f_ds.Copy();
                //DataRow drnew;
                //drnew = f_ds.Tables[0].NewRow();
                //drnew["asn_type"] = "";
                //f_ds.Tables[0].Rows.Add(drnew);
                ds_move = f_ds.Copy();
                comboBox2.ValueMember = "dictionary_code";
                comboBox2.DisplayMember = "move_trans";
                comboBox2.DataSource = f_ds.Tables[0].Copy();
                DataSet ds_new = f_ds.Copy();
                ds_new.Tables[0].Rows.Clear();
                DataRow drnew;
                drnew = ds_new.Tables[0].NewRow();
                drnew["dictionary_code"] = "";
                drnew["move_trans"] = "";
                ds_new.Tables[0].Rows.Add(drnew);
                for (int i = 0; i < f_ds.Tables[0].Rows.Count; i++)
                {
                    DataRow drnew2;
                    drnew2 = ds_new.Tables[0].NewRow();
                    drnew2["dictionary_code"] = f_ds.Tables[0].Rows[i]["dictionary_code"].ToString().Trim();
                    drnew2["move_trans"] = f_ds.Tables[0].Rows[i]["move_trans"].ToString().Trim();
                    ds_new.Tables[0].Rows.Add(drnew2);
                }
                comboBox1.ValueMember = "dictionary_code";
                comboBox1.DisplayMember = "move_trans";
                comboBox1.DataSource = ds_new.Tables[0].Copy();

            }
            catch (System.Exception ee)
            {
                MessageBox.Show(main.g_class.comm_getchangestring("Fail to initialize Information of bill's type", main.g_info_dataset) + "!" + ee.ToString());
                return;
            }
            cb_q_status.Text = "";
        }

        private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void dataGridView1_SelectionChanged(object sender, EventArgs e)
        {
            if (dataGridView1.CurrentRow != null)
            {
                string str_sql = "";
                string where1 = "";
                string where2 = "";
                where1 = " and moveout_pallet='0' and batchno='0' and main_dist <> 'D'  ";
                where2 = " and moveout_pallet<>'0' and batchno<>'0' and main_dist <> 'D' ";
                move_no_str = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["move_no_h"].Value.ToString().Trim();
                str_sql_where = "inv_org = '" + main.g_org + "' and consignor='" + dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["consignor"].Value.ToString().Trim() + "' and move_no='" + dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["move_no_h"].Value.ToString().Trim() + "'";
                //取确认状态
                g_str_status = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["move_status"].Value.ToString().Trim();
                g_str_status = main.g_class.comm_getconversestring(g_str_status, main.g_info_dataset);
                switch (g_str_status.Trim().ToLower())
                {
                    case "make":
                        g_str_status = "0";
                        break;
                    case "part confirm":
                        g_str_status = "1";
                        break;
                    case "confirm":
                        g_str_status = "2";
                        break;
                    case "closed":
                        g_str_status = "3";
                        break;
                    default:
                        g_str_status = "";
                        break;
                }

                if (g_str_status == "3" || g_str_status == "2")
                {
                    bt_Direction.Enabled = false;
                    if (g_str_status == "3")
                    {
                        bt_Close.Enabled = false;
                    }
                    else
                    {
                        bt_Close.Enabled = true;
                    }
                }
                else
                {
                    bt_Direction.Enabled = true;
                    bt_Close.Enabled = true;
                }

                DataRow[] tr_header = dsmove_header.Tables[0].Select(str_sql_where);
                if (tr_header.Length > 0)
                {
                    show(tr_header[0]);

                    dsmove_mv = new DataSet();
                    dsmove_con = new DataSet();
                    if (str_type == "0")
                    {
                        str_sql = "select a.*,confirm_qty_m as old_confirm_qty_m,0.0 tmp_qty from " + main.g_space + ".inv_move_detail a where " + str_sql_where;
                        if (main.dbtype == "SQL")
                        {

                            str_sql_mv = str_sql + where1;
                            dsmove_mv = main.dbservice.Sql_exec_selectsql(str_sql_mv);
                            str_sql_con = str_sql + where2;
                            dsmove_con = main.dbservice.Sql_exec_selectsql(str_sql_con);

                        }
                        else
                        {
                            str_sql_mv = str_sql + where1;
                            dsmove_mv = main.dbservice.oracle_exec_selectsql(str_sql_mv);
                            str_sql_con = str_sql + where2;
                            dsmove_con = main.dbservice.oracle_exec_selectsql(str_sql_con);
                        }
                        dataGridView2.DataSource = dsmove_mv.Tables[0];

                        dataGridView3.DataSource = dsmove_con.Tables[0];
                    }
                    else
                    {
                        str_sql = " select a.*,a.confirm_qty_m as old_confirm_qty_m " +
                              "  from " + main.g_space + ".inv_move_detail a ," + main.g_space + ".inv_sku_pallet b" +
                                     " where a.inv_org=b.inv_org and a.consignor=b.consignor and a.moveout_location=b.location_code and a.batchno=b.batchno and a.moveout_pallet=b.pallet_no " +
                                     " and a.sku=b.sku   " +
                                     " and a.inv_org = '" + main.g_org + "' and a.move_no='" + dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["move_no_h"].Value.ToString().Trim() + "' and a.consignor='" + dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["consignor"].Value.ToString().Trim() + "'";
                        where1 = "";
                        where2 = " and a.move_status in ('1','2')  ";
                        str_update_sql = "select a.*,confirm_qty_m as old_confirm_qty_m,0.0 tmp_qty from " + main.g_space + ".inv_move_detail a where inv_org = '" + main.g_org + "' and move_no='" + dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["move_no_h"].Value.ToString().Trim() + "' and consignor='" + dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["consignor"].Value.ToString().Trim() + "'";
                        if (main.dbtype == "SQL")
                        {
                            str_sql_mv = str_sql + where1;
                            dsmove_mv = main.dbservice.Sql_exec_selectsql(str_sql_mv);
                            str_sql_con = str_sql + where2;
                            dsmove_con = main.dbservice.Sql_exec_selectsql(str_sql_con);

                        }
                        else
                        {
                            str_sql_mv = str_sql + where1;
                            dsmove_mv = main.dbservice.oracle_exec_selectsql(str_sql_mv);
                            str_sql_con = str_sql + where2;
                            dsmove_con = main.dbservice.oracle_exec_selectsql(str_sql_con);
                        }
                        dataGridView2.DataSource = dsmove_mv.Tables[0];
                        dataGridView3.DataSource = dsmove_con.Tables[0];
                    }
                }
            }
        }

        private void dataGridView3_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
             int row_no;
             if (dataGridView3.CurrentRow != null)
             {
                 row_no = e.RowIndex;
                 if (row_no >= 0)
                 {
                     if (dataGridView3.Columns[e.ColumnIndex].Name.ToString().Trim() == "E_confirm_qty_m")
                     {
                         try
                         {
                             if (String.IsNullOrEmpty(e.FormattedValue.ToString()))
                             {

                             }
                             else
                             {
                                 double d_cubage = Math.Round(Convert.ToDouble(dataGridView3.Rows[e.RowIndex].Cells["E_confirm_cubage"].Value.ToString().Trim()) / Convert.ToDouble(dataGridView3.Rows[e.RowIndex].Cells["Old_stock_qty_m"].Value.ToString().Trim()), 4);
                                 double d_gross_weight = Math.Round(Convert.ToDouble(dataGridView3.Rows[e.RowIndex].Cells["E_confirm_gross_weight"].Value.ToString().Trim()) / Convert.ToDouble(dataGridView3.Rows[e.RowIndex].Cells["Old_stock_qty_m"].Value.ToString().Trim()), 4);
                                 double d_net_weight = Math.Round(Convert.ToDouble(dataGridView3.Rows[e.RowIndex].Cells["E_confirm_net_weight"].Value.ToString().Trim()) / Convert.ToDouble(dataGridView3.Rows[e.RowIndex].Cells["Old_stock_qty_m"].Value.ToString().Trim()), 4);
                                 //double dnum3=Convert.ToDouble(dataGridView3.Rows[e.RowIndex].Cells["temp_qty"].Value.ToString().Trim());
                                 double dnum = Convert.ToDouble(dataGridView3.Rows[e.RowIndex].Cells["Old_stock_qty_m"].Value.ToString().Trim());
                                 double dnum2 = Convert.ToDouble(e.FormattedValue.ToString());
                                 //if (dnum2 > dnum3)
                                 //{
                                 //    dataGridView3.Rows[e.RowIndex].ErrorText = "移库数大于可用数量";
                                 //    MessageBox.Show("移库数大于可用数量");
                                 //    e.Cancel = true;
                                 //}    
                                  if (dnum2 > dnum)
                                 {
                                     dataGridView3.Rows[e.RowIndex].ErrorText = "移库数大于可用数量";
                                     MessageBox.Show("移库数大于可用数量");
                                     e.Cancel = true;
                                 }                                
                                 else //计算重量体积
                                 {

                                     dataGridView3.Rows[row_no].Cells["E_confirm_qty_s"].Value = Math.Round(Convert.ToDouble(dataGridView3.Rows[row_no].Cells["convert_modulus"].Value.ToString().Trim()) * dnum2, 4);

                                     dataGridView3.Rows[row_no].Cells["E_confirm_cubage"].Value = Math.Round(d_cubage * dnum2, 4); ;

                                     dataGridView3.Rows[row_no].Cells["E_confirm_gross_weight"].Value = Math.Round(d_gross_weight * dnum2, 4); ;

                                     dataGridView3.Rows[row_no].Cells["E_confirm_net_weight"].Value = Math.Round(d_net_weight * dnum2, 4); ;
                                     dataGridView3.Rows[row_no].Cells["E_confirm_qty_m"].Value = dnum2;
                                 }
                             }
                         }
                         catch (Exception)
                         {
                             dataGridView3.Rows[e.RowIndex].ErrorText = "必须输入数字";
                             MessageBox.Show("请输入数字 ");
                             e.Cancel = true;
                         }
                     }
                 }
             }
        }
    }

}

